当鼠标停留在DOM对象上时,有没有JavaScript或jQuery解决方案可以重复运行一个函数(在setTimeout之后)?换句话说,有没有JavaScript“在鼠标悬停时做”(或者“如果鼠标悬停”)?
$('someObject').bind('mouseover', function() {
//Do the following while mouseover
$('someOtherObject').css('margin-left',adjustedLeft + 'px');
setTimeout(/*do it again*/,25);
});发布于 2010-10-19 15:58:03
$('someObject').on('mouseenter', function() {
this.iid = setInterval(function() {
// do something
}, 25);
}).on('mouseleave', function(){
this.iid && clearInterval(this.iid);
});Example Look here
发布于 2010-10-19 15:57:41
我会使用onmouseout事件来解决这个问题。当鼠标悬停在mouseover事件的指定组件上时,启动您想要执行的任何操作。当onmouseout事件发生时,我会停止它。
发布于 2013-12-07 00:32:39
我知道这有点老了,但我认为JavaScript中已经有了合适的函数,onmousemove就是这么做的。
https://stackoverflow.com/questions/3966273
复制相似问题