如何觸發鼠標點擊元素(滑塊「下一個」按鈕)每X秒?觸發鼠標點擊一個按鈕每5秒
我已經在Adobe Muse中構建了一個網站,但滑塊小部件沒有自動播放功能,並且我正在嘗試每5秒鐘點擊一下按鈕以模擬自動播放。我發現按鈕類
<div class="fp-controlArrow fp-next"></div>
也許甚至有機會以某種方式觸發點擊它?由於
如何觸發鼠標點擊元素(滑塊「下一個」按鈕)每X秒?觸發鼠標點擊一個按鈕每5秒
我已經在Adobe Muse中構建了一個網站,但滑塊小部件沒有自動播放功能,並且我正在嘗試每5秒鐘點擊一下按鈕以模擬自動播放。我發現按鈕類
<div class="fp-controlArrow fp-next"></div>
也許甚至有機會以某種方式觸發點擊它?由於
我必須指定兩類觸發按鈕,使用有點難度命令停止它。這工作:
var interval = setInterval(function() {
document.querySelector('.fp-controlArrow.fp-next').click();
}, 5000);
現在我有更多的問題:是否有可能阻止用戶點擊後會單擊後退或前進按鈕的鼠標?
作爲半措施,我將它設置爲停在它返回到第一張幻燈片,但它會更好,以阻止它用戶點擊任意按鈕後,一時間......
var interval = setInterval(function() {
document.querySelector('.fp-controlArrow.fp-next').click();
}, 7000);
setTimeout(function() { clearInterval(interval); }, 44000);
謝謝
你可以存儲在一個變量的區間,只要你想
var interval = setInterval(function() {
button.click();
// [button] here is the element you found with the specified class
// if you're using jQuery
// you can get you button and trigger the event
// beware of other buttons using the same class
jQuery(".fp-next").trigger("click");
}, 5000);
//if you want to stop it
clearInterval(interval);