【问题标题】:how to implement mousemove after mousedown using js如何使用js在mousedown后实现mousemove
【发布时间】:2015-06-11 06:59:58
【问题描述】:

我需要在 mouse down 之后实现一个 mouse over ,这样当用户按下并移动单元格时就会打开(扫雷)

这是我的代码!

case 2:
    {
        if ($(this).hasClass("open") || $(this).hasClass("bomb") || $(this).hasClass("close")) {
            var X_axis;
            var Y_axis;
            $('.close').mousemove(function (event2) {
                if ($(this).attr('row') != X_axis && $(this).attr('column') != Y_axis) {
                    var obj = $("[row='" + X_axis + "'][column='" + Y_axis + "']");
                    $(obj).addClass("close");
                }
                $(this).removeClass("close");
                X_axis = $(this).attr('row');
                Y_axis = $(this).attr('column');
            });
        }
    }
    break;


case 2 --> mean left mouse click 

【问题讨论】:

  • 你对上面的代码有什么具体问题吗?
  • 是的,当用户按下一个单元格并移动到另一个单元格时,
  • 上一个单元格必须关闭

标签: javascript jquery mouseevent mousemove mousedown


【解决方案1】:

抱歉,解决办法是这样的

 if ($(this).attr('row') != X_axis || $(this).attr('column') != Y_axis)

使用 ||不是 && ,因为数组 2d 并且可能当前单元格 x_axis 等于前一个单元格 x_axis ....

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多