Java脚本:mousestop事件(Java Script: mousestop event)
对于某些功能,我正在处理mousemove事件。 mousemove事件侦听器在一个不需要的单个线性鼠标手势中被多次调用。 我需要实现一个自定义事件,当鼠标停止运动时将调用该事件。 我猜它可以在mousemove上实现一些延迟功能。
请帮助我这方面。 谢谢
For some feature, I am working on mousemove event. mousemove event listener is invoked a number of times with in a single linear mouse gesture that is not required. I need to implement a custom event that will be invoked when mouse will stop its motion. I have a guess that it can be implemented on top of mousemove with some delay feature.
Please help me in this regard. Thanks
原文:https://stackoverflow.com/questions/3262501
更新时间:2020-03-02 15:10
最满意答案
你大部分时间都在那里:
function waitForMouseStop(callback) {
var timer;
function stoppedMoving(evt) {
document.onmousemove = null;
callback();
}
function moveHandler(evt) {
evt = evt || window.event;
if (timer) {
window.clearTimeout(timer);
}
timer = window.setTimeout(function() {
stoppedMoving(evt);
}, 500);
}
document.onmousemove = moveHandler;
}
waitForMouseStop(function() {
alert("Stopped");
});
You're most of the way there:
function waitForMouseStop(callback) {
var timer;
function stoppedMoving(evt) {
document.onmousemove = null;
callback();
}
function moveHandler(evt) {
evt = evt || window.event;
if (timer) {
window.clearTimeout(timer);
}
timer = window.setTimeout(function() {
stoppedMoving(evt);
}, 500);
}
document.onmousemove = moveHandler;
}
waitForMouseStop(function() {
alert("Stopped");
});
2010-07-19
相关问答
只需在drop事件中调用控制器上的操作即可。 您可以像这样使用jQuery : $.ajax({
type: "POST",
url: yourUrl,
data: dataSerializedAsJson,
success: function() { /* action */ },
dataType: "json"
});
Just call an action on your controller in the drop event. You can use jQuery
...
将函数名称作为字符串传递确实是一个坏主意。 以字符串格式附加代码也是如此,例如"(this.getAttribute('"+param_trs+"'))" 。 这将需要解析,就像eval一样。 效率低,可能导致与eval相关的问题 。 函数可以作为参数传递,而不是作为字符串传递,而是作为实际函数引用。 其次,事件处理程序函数在执行时检索属性值更合适,而不是之前。 所以这是一个提出这个想法的片段。 该演示将采用data-inc属性来确定应该增加多少数量。 function addEventListe
...
啊,这很简单。 感谢所有答案。 方案 : 对服务器端事件使用OnClick属性,对客户端事件使用OnClientclick进行验证。 OnClientClick javascript方法将返回true和false ,它决定了serveride onclick事件是否会触发。 代码将是这样的
function DoPost() {
var chk = document.getElementById('
...
除了missing () ,你的代码工作正常,试试吧: var main = function(){
$(".submitbtn").click(function() {
alert("yay");
});
};
$(document).ready(main); .submitbtn {background: orange; cursor: pointer; float: left; padding: .2em 1em; }
这将“自动点击”按钮,从而触发处理其点击的任何服务器端代码。 If Button1 already exists, have such code:
jQuery("#textbox").blur(function() {
ajaxFunction(jQuery("#textbox").val());
试试这个希望完全有这个帮助。 I finally got the solution.