gpt4 book ai didi

javascript - 如何在mouseDown按下js时实现mousemove

转载 作者:数据小太阳 更新时间:2023-10-29 05:01:06 25 4
gpt4 key购买 nike

只有在按下鼠标时我才需要实现鼠标移动事件。

只有当鼠标按下和移动时,我才需要执行“OK Moved”。

我用过这段代码

 $(".floor").mousedown(function() {
$(".floor").bind('mouseover',function(){
alert("OK Moved!");
});
})
.mouseup(function() {
$(".floor").unbind('mouseover');
});

最佳答案

使用 mousemove 事件。

来自 mousemovemouseover jquery 文档:

The mousemove event is sent to an element when the mouse pointer moves inside the element.

The mouseover event is sent to an element when the mouse pointer enters the element.

示例:(检查控制台输出)

$(".floor").mousedown(function () {
$(this).mousemove(function () {
console.log("OK Moved!");
});
}).mouseup(function () {
$(this).unbind('mousemove');
}).mouseout(function () {
$(this).unbind('mousemove');
});

https://jsfiddle.net/n4820hsh/

关于javascript - 如何在mouseDown按下js时实现mousemove,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30817534/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com