JavaScript / jQuery中的“if mouseover”或“do while mouseover”
是否有JavaScript或jQuery解决方案在鼠标hover在DOM对象上时重复运行函数(在setTimeout
之后)? 否则说,有没有JavaScript“做鼠标hover”(或“如果鼠标hover”)?
$('someObject').bind('mouseover', function() { //Do the following while mouseover $('someOtherObject').css('margin-left',adjustedLeft + 'px'); setTimeout(/*do it again*/,25); });
$('someObject').on('mouseenter', function() { this.iid = setInterval(function() { // do something }, 25); }).on('mouseleave', function(){ this.iid && clearInterval(this.iid); });
示例请看这里
我会使用onmouseout事件解决这个问题。 当鼠标hover在mouseover事件上的指定组件上时,启动您打算执行的任何操作。 当onmouseout事件发生时,我会阻止它。
我使用jQuery的新绑定样式。
$(EL).bind({ 'mouseenter':function(){console.log('Mouse over');}, 'mouseleave':function(){console.log('Mouse leave');} });
我知道这有点旧 ,但我认为正确的function已经在JavaScript中, onmousemove就是这样。