当您快速移动鼠标时,鼠标移动速度会变慢
我试图让jquery框拖动,但问题是,当我拖动得非常快时,“mousemove”的移动速度比我的鼠标慢,当鼠标离开拖动#box时,mousemove不会移动,我该如何解决这个问题? :
function position(div,x,y) {
x = x-100;
y = y-100;
$(div).css({'left':x, 'top':y});
}
$(document).ready(function() {
var check = false;
$("#box").mousedown(function() {
check = true;
$("#box").mousemove(function (e) {
if(check != false) {
position("#box", e.pageX, e.pageY);
}
});
}).mouseup(function() {
check = false;
});
});
im trying to make jquery box drag, but the problem is that when i drag really fast the "mousemove" is moving slower than my mouse and when the mouse gets out of the dragging #box the mousemove wont move, how can i fix this?:
function position(div,x,y) {
x = x-100;
y = y-100;
$(div).css({'left':x, 'top':y});
}
$(document).ready(function() {
var check = false;
$("#box").mousedown(function() {
check = true;
$("#box").mousemove(function (e) {
if(check != false) {
position("#box", e.pageX, e.pageY);
}
});
}).mouseup(function() {
check = false;
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它的速度变慢是因为您使用了太多的系统资源。所以你需要找到减少系统使用的方法。
通过将鼠标移动延迟到文档,它的运行速度会更快一些。当您快速移动鼠标时,它仍然有点滞后,但这是一个改进。这是代码:
It's slowing down because you are using too many system resouces. So you need to find ways to reduce system usage.
By delagating the mousemove to document, it runs a bit faster. It still lags a bit when you move the mouse really fast, but it's an improvement. Here's the code: