我将一个mouseenter/mouseleave事件绑定到一个元素(仅仅是一个图像),然后执行两个函数。我的问题是,我希望这两个函数中的一个只在第一个mouseenter上触发一次。jQuery两个mouseenter事件,触发一个函数ONCE
aka在第一个mouseenter上发生了两件事,在第二件mouseneter上只发生了一件事。
$(.bubbles).mouseenter(function(){
functionSwapImage(); //this should happen everytime
}).mouseleave(function(){
functionSwapImageBack(); //this should happen everytime
$(".bubbles").one("mouseleave", function(){
myFunction(); //this should happen once!
});
});
如果我移动.one
功能块之外,进入它自己单独的鼠标进入/离开块,那么functionSwapImageBack()
只能触发一次(即。一是删除事件对于这两个代码块)。
不太清楚该怎么做,但感谢您的帮助!
看起来不错,但你需要移动块外的'one'功能。否则每当鼠标离开时它都会被绑定 –
我是否必须编辑html?我该如何处理“onlyonce”命名空间?即'myFunction(){console.log(“good”); }'应该是什么样子? – jaredrada
@BrianGlaz - 不错的点就错过了。 – ShankarSangoli