gpt4 book ai didi

jquery mousemove如何停止

转载 作者:行者123 更新时间:2023-12-01 00:06:30 25 4
gpt4 key购买 nike

我有这个 fiddle http://jsfiddle.net/JqBZb/193/我希望我的对象仅在按下红色方 block 时移动,但当用户释放鼠标时我无法删除鼠标移动操作。之后它仍然会移动。

HTML:

<div class="pointer">
<div class="marker"></div>
</div>

CSS:

.marker {
background:#ED1C24;
height:2px;
right:0;
position:absolute;
top:35px;
width:7px
}
.pointer {
height:72px;
position:absolute;
top:82px;
width:72px;
border:1px solid red;
left:100px;
}

JavaScript:

var img = $('.pointer');

var offset = img.offset();

function mouse(evt) {
var center_x = (offset.left) + (img.width() / 2);
var center_y = (offset.top) + (img.height() / 2);
var mouse_x = evt.pageX;
var mouse_y = evt.pageY;
var radians = Math.atan2(mouse_x - center_x, mouse_y - center_y);
var degree = (radians * (180 / Math.PI) * -1) + 90;
img.css('-moz-transform', 'rotate(' + degree + 'deg)');
img.css('-webkit-transform', 'rotate(' + degree + 'deg)');
img.css('-o-transform', 'rotate(' + degree + 'deg)');
img.css('-ms-transform', 'rotate(' + degree + 'deg)');
}

img.mousedown(function (e) {
$(document).mousemove(mouse);
}).mouseup(function (e) {
e.stopPropagation();
})

原始轮换脚本由此答案提供 https://stackoverflow.com/a/10235298/1168944

最佳答案

将其添加到您的脚本中...

$(document).mouseup(function() {
$(document).off("mousemove", mouse);
});

只要您释放鼠标按钮,它就会解除绑定(bind) mousemove 事件处理程序。

http://jsfiddle.net/JqBZb/201/

我也将其更新到更高版本的 jQuery,以适应 off()

关于jquery mousemove如何停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18589948/

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