-2
我創建一個滑塊並使用setTimeout函數每5秒自動更改一次類名稱。clearTimeout不支持單擊事件
我想我每次點擊幻燈片選擇再次復位定時器但它並不無論我做什麼了clearTimeout只是不從下面燒
function autoAddClass(){
console.log('changing class');
setTimeout(autoAddClass, 1000);
}
setTimeout(autoAddClass, 1000); // to run the function on load
$('.post-nav-btn').on('click',function(e){
e.preventDefault();
clearTimeout(autoAddClass);
});
again..pseudo代碼停止功能
您沒有正確使用clearTimeout。通過https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/clearTimeout閱讀它 – j08691