如何使用JS在鼠标按下后实现鼠标移动

how to implement mousemove after mousedown using js

本文关键字:鼠标 实现 移动 JS 何使用      更新时间:2023-09-26

我需要在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 
哦,

对不起,这是解决方案

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

使用 || 不是 &&,因为数组 2D 和当前单元格x_axis等于以前的单元格x_axis....