这个问题一直困扰着我。我使用滑块作为我的应用程序。对于滑动应用程序,我正在使用夹板-js。我的图像滑块很好用。
我已经将滑块与我的li元素连接起来。我想要定制onmouseover和onmouseout事件。当用户在mouseover上触发li时,它将暂停,当mouseout将恢复幻灯片时。
我正在检查这个堆叠溢出柱,并试图通过使用setinterval来像人一样执行逻辑,但无法做到。
const autoPlay = false;
const pauseOnHover = document.getElementById('pause');
function nextSlide() { //I don't what kind logic I should use to pause the slide
}
let timer = setInterval(function() {
nextSlide();
}, 400);
pauseOnHover.onmouseover = () => {
if( autoPlay) {
timer
}
}
pauseOnHover.onmouseout = () => {
if (autoPlay) {
clearInterval(timer)
}
}<div class='checklist' id="pause">
<ol>
<li id="link-1">Assign jobs in an instant.</li>
<li id="link-2">Always see what's happening.</li>
<li id="link-3">Easy to set-up & use.</li>
<li id="link-4">Be more sustainable</li>
</ol>
</div>
发布于 2020-08-21 04:15:57
请输入并恢复鼠标悬停时的间隔,如果存在间隔,请取消。
请试试下面的代码。
const autoPlay = false;
const pauseOnHover = document.getElementById('pause');
function nextSlide() {
//For example I have put console.log, you mat put any code block here.
console.log("hello");
}
let timer;
pauseOnHover.onmouseover = () => {
autoplay = true;
if (!autoPlay) {
autoplay = true;
timer = setInterval(function() {
nextSlide();
}, 400);
}
}
pauseOnHover.onmouseout = () => {
autoplay = false;
timer && clearInterval(timer)
}<div class='checklist' id="pause">
<ol>
<li id="link-1">Assign jobs in an instant.</li>
<li id="link-2">Always see what's happening.</li>
<li id="link-3">Easy to set-up & use.</li>
<li id="link-4">Be more sustainable</li>
</ol>
</div>
https://stackoverflow.com/questions/63516374
复制相似问题