【发布时间】:2021-05-27 05:19:02
【问题描述】:
我遇到了在 mouseenter 上触发并循环的函数的问题。问题是我想在鼠标离开时停止。
尝试了一些东西,但似乎没有按预期工作。
HTML
<div class="trigger">Hover me to trigger animation</div>
<div class="logo-tagline">
<span>Simple.</span>
<span>Fast.</span>
<span>Around you.</span>
</div>
jQuery
$( ".trigger" ).mouseenter(function() {
function highlight(items, index) {
index = index % items.length;
items.removeClass("-visible");
items.eq(index).addClass('-visible');
setTimeout(function() {
highlight(items, index + 1)
}, 1000);
}
highlight($('.logo-tagline span'), 0);
});
【问题讨论】:
标签: jquery foreach mouseleave