关于JS悬停延时加载函数的问题 js悬停 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 除了setTimeout,你还有神马好方法。 使用setTimeout的话,只要鼠标一晃过,隔一段时间就会加载指定的函数了,想要的是用户必须悬停700ms才加载 var clock = '';xxx.mouseover = function(){ clearTimeout(clock); clock = setTimeout(function(){ //..... },700);}这样不行吗 var clock = '';1.DOMObj.onmouseover = function(){ clearTimeout(clock); clock = setTimeout(function(){ //..... },700);}2.$(xxx).mouseover(function(){ clearTimeout(clock); clock = setTimeout(function(){ //..... },700);});一开始写错了 谢谢回复。但是这个版本其实只是用了jquery,和setTimeout好像没什么大的区别吧? jQuery只不过被人封装了一下而已,还一样是JS。用下面那个var clock = '';$(xxx).mouseover(function(){ clearTimeout(clock); clock = setTimeout(function(){ //..... },700);}); 你把要加载的函数写在setTimeout里面的匿名函数里面var clock = '';$(xxx).mouseover(function(){ clearTimeout(clock); clock = setTimeout(function(){ //要调用的函数写这里 },700);}); var clock = '';$('.cover').mouseover(function(){clearTimeout(clock);clock = setTimeout(function(e){//要调用的函数写这里floatDiv(e,'cover0');},1000);});我就是按照你说的这么写的,鼠标晃过的时候犹如闪电一般,但还是加载了floatDiv函数 mouseout的时候你也执行一下clearTimeout(clock); var obj = document.getElementById("txt1");obj.onmouseover = function(){obj.isOver = true;setTimeout(function(){if(!obj.isOver)return;//do sth.},700);}obj.onmouseout = function(){try{delete obj.isOver;}catch{obj.isOver = undefined;}} button.addEventListener( 'mouseover', function(event) { showClothTimer = setTimeout(function(){ alert(1); },10000); }, false );10秒后弹出,我试过把要执行的内容写在一个函数里面,效果和楼主遇到的情况一样,但是吧要执行的写成上面的情况就不会立即执行。 var t;$(function(){ $('#test').hover(function(){ t = setTimeout(function(){ // TO DO },700); },function(){ if(t) clearTimeout(t); })}) 要測試用戶滑鼠是否悬停的話用mouseover 無解吧請改用mousemove且同10樓所說 mousemove執行時也執行clearTimeout <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <script type="text/javascript"> var mytimer = null; function beginEvent(){ mytimer = window.setTimeout("myfunc('123','456')", 500); } function cancelEvent() { clearTimeout(mytimer); } function myfunc(t1,t2) { var d = document.getElementById("div1"); d.innerText = new Date(); clearTimeout(mytimer); mytimer = null; } </script> </head> <body> <br/> <br/> <div id="div1" style="position: absolute; top: 100px; left: 100px; width: 100px; height: 100px; border: 1px solid black;" onmouseover="beginEvent()" onmouseout="cancelEvent()"></div> </body> </html> iframe页面上的按钮重定向当前子页面的问题 javascript写在页面中和JS文件引用有什么区别? Window.location.href 如何连接到同一工程另个目录下的页面? 变量加载数据 window.open()怎么指定弹出的窗口的位置? 现有两个数组A与B,数组的结构与长度相同,根据需要删除A中某位置的值,同时删除数组B中相应位置的值。请问有什么好的方法吗? 这种效果怎么实现. 页面的提交有提交文字数量和文字数量的限制吗 高分求教问题? 如何用javascript禁止掉IE的快捷键,比如“前进”“后退”等? js png透明ie6不管用 Jquery
xxx.mouseover = function(){
clearTimeout(clock);
clock = setTimeout(function(){
//.....
},700);
}这样不行吗
1.
DOMObj.onmouseover = function(){
clearTimeout(clock);
clock = setTimeout(function(){
//.....
},700);
}
2.
$(xxx).mouseover(function(){
clearTimeout(clock);
clock = setTimeout(function(){
//.....
},700);
});一开始写错了
$(xxx).mouseover(function(){
clearTimeout(clock);
clock = setTimeout(function(){
//.....
},700);
});
$(xxx).mouseover(function(){
clearTimeout(clock);
clock = setTimeout(function(){
//要调用的函数写这里
},700);
});
$('.cover').mouseover(function(){
clearTimeout(clock);
clock = setTimeout(function(e){
//要调用的函数写这里
floatDiv(e,'cover0');
},1000);
});
我就是按照你说的这么写的,鼠标晃过的时候犹如闪电一般,但还是加载了floatDiv函数
var obj = document.getElementById("txt1");
obj.onmouseover = function(){
obj.isOver = true;
setTimeout(function(){
if(!obj.isOver)
return;
//do sth.
},700);
}obj.onmouseout = function(){
try{
delete obj.isOver;
}catch{
obj.isOver = undefined;
}
}
showClothTimer = setTimeout(function(){
alert(1);
},10000);
}, false );
10秒后弹出,我试过把要执行的内容写在一个函数里面,效果和楼主遇到的情况一样,但是吧要执行的写成上面的情况就不会立即执行。
var t;
$(function(){
$('#test').hover(function(){
t = setTimeout(function(){
// TO DO
},700);
},function(){
if(t) clearTimeout(t);
})
})
用mouseover 無解吧請改用mousemove
且同10樓所說
mousemove執行時也執行clearTimeout
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript">
var mytimer = null;
function beginEvent(){
mytimer = window.setTimeout("myfunc('123','456')", 500);
}
function cancelEvent() {
clearTimeout(mytimer);
}
function myfunc(t1,t2) {
var d = document.getElementById("div1");
d.innerText = new Date();
clearTimeout(mytimer);
mytimer = null;
}
</script>
</head>
<body>
<br/>
<br/>
<div id="div1" style="position: absolute; top: 100px; left: 100px; width: 100px; height: 100px; border: 1px solid black;" onmouseover="beginEvent()" onmouseout="cancelEvent()"></div>
</body>
</html>