所以我在 aspx 页面上有一个控件(地图)。我想编写一些 javascript 来设置以下内容:
当鼠标在控件上停止时 = 一些代码
当鼠标移动 = 一些代码时(但仅当移动时间超过 250 mil 秒时)
这可以在停止时触发代码,然后在移动时触发......
function setupmousemovement() {
var map1 = document.getElementById('Map_Panel');
var map = document.getElementById('Map1');
map1.onmousemove = (function() {
var onmousestop = function() {
//code to do on stop
}, thread;
return function() {
//code to do on mouse move
clearTimeout(thread);
thread = setTimeout(onmousestop, 25);
};
})();
};
但我不知道如何在移动代码中引入延迟。我以为我有这个...
function setupmousemovement() {
var map1 = document.getElementById('Map_Panel');
var map = document.getElementById('Map1');
map1.onmousemove = (function() {
var onmousestop = function() {
//code to do on stop
clearTimeout(thread2);
}, thread;
return function() {
thread2 = setTimeout("code to do on mouse move", 250);
clearTimeout(thread);
thread = setTimeout(onmousestop, 25);
};
})();
};
但它的行为并不像我想象的那样。移动中的“thread2”永远不会被停止清除。我错过了什么?