Jquery mouseleave上的停止功能
我对mouseenter上的触发器和它的循环有问题。问题是我想在mouseleave上停止运行 尝试了几件事,但似乎没有任何效果 HTML 链接到我的笔:Jquery mouseleave上的停止功能,jquery,foreach,mouseleave,Jquery,Foreach,Mouseleave,我对mouseenter上的触发器和它的循环有问题。问题是我想在mouseleave上停止运行 尝试了几件事,但似乎没有任何效果 HTML 链接到我的笔: 您只需清除设置超时,如下所示 不过请注意,根据是否要再次隐藏文本,这取决于您自己,因此请相应地进行处理 let timeoutFunc; function highlight(items, index) { index = index % items.length; items.removeClass(&qu
- 您只需清除
,如下所示设置超时
- 不过请注意,根据是否要再次隐藏文本,这取决于您自己,因此请相应地进行处理
let timeoutFunc; function highlight(items, index) { index = index % items.length; items.removeClass("-visible"); items.eq(index).addClass('-visible'); timeoutFunc = setTimeout(function() { highlight(items, index + 1) }, 1000); } $( ".trigger" ).mouseenter(function() { highlight($('.logo-tagline span'), 0); }); $( ".trigger" ).mouseleave(function() { $('.-visible').removeClass("-visible"); clearTimeout(timeoutFunc); });
你能帮我去掉mouseleave上的“-visible”类吗?非常感谢!
$( ".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);
});
let timeoutFunc;
function highlight(items, index) {
index = index % items.length;
items.removeClass("-visible");
items.eq(index).addClass('-visible');
timeoutFunc = setTimeout(function() {
highlight(items, index + 1)
}, 1000);
}
$( ".trigger" ).mouseenter(function() {
highlight($('.logo-tagline span'), 0);
});
$( ".trigger" ).mouseleave(function() {
$('.-visible').removeClass("-visible");
clearTimeout(timeoutFunc);
});
$( ".trigger" ).mouseenter(startInterval);
$( ".trigger" ).mouseleave(stopInterval);
// You'll need a variable to store a reference to the timer
var timer = null;
function startInterval() {
/* Your Function Code HERE */
// Then you initilize the variable
timer = setInterval(function() {
console.log("Foo Executed!");
}, 1500);
}
function stopInterval() {
// To cancel an interval, pass the timer to clearInterval()
clearInterval(timer);
}