JavaScript實現(xiàn)頁面無操作倒計時退出
更新時間:2016年10月22日 08:42:10 作者:尖峰時刻
這篇文章主要為大家詳細介紹了JavaScript實現(xiàn)頁面無操作倒計時退出,具有一定的參考價值,感興趣的小伙伴們可以參考一下
項目前端頁面需要實現(xiàn),頁面沒人操作進入倒計時,以下為前端代碼實現(xiàn)。
//設置(倒計時功能)開關 var _mouseActiveListener_flag = true;
beforecount:觸發(fā)倒計時間隔(單位:毫秒)
count:倒計時總數(shù)(單位:秒)
var mouseActiveListener = function (beforecount, count, callback) { //config var __countdown_html = '<div id="__tt" style="position:fixed;top:110px;right:10px;z-index:1000;color:#eee;font-size:25px;"></div>'; //define var target = null, _t = null, _tc = null; var target_countdown = function (__count) { if (__count >= 0) { target.innerHTML = __count + '秒后退出'; _tc = setTimeout(function () { target_countdown(__count); }, 1000); } else { callback(); } __count--; }, _t_exec = function () { return setTimeout(function () { if (_mouseActiveListener_flag) { target = Ne.dom.createEl(__countdown_html); document.body.appendChild(target); target_countdown(count); } }, beforecount); }, _t_clear = function () { clearTimeout(_t); clearTimeout(_tc); //target.parentElement.removeChild(target); $(target).remove(); target = null; }; //exec _t = _t_exec(); document.addEventListener('click', function () { _t_clear(); _t = _t_exec(); }); };
//后置操作,解釋:在5秒后(5000)不操作的狀態(tài)下觸發(fā)倒計時,倒計時180秒,具體看View Code里面的函數(shù)。 mouseActiveListener(5000, 180, function () { window.location.href = "/Home/Index"; });
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
JavaScript 全面解析各種瀏覽器網(wǎng)頁中的JS 執(zhí)行順序
近來我通過一些測試以全面的解析網(wǎng)頁在各種瀏覽器中的JavaScript代碼的執(zhí)行順序,在這兒做個記錄。2009-02-02JavaScript canvas實現(xiàn)雪花隨機動態(tài)飄落
這篇文章主要為大家詳細介紹了JavaScript canvas實現(xiàn)雪花隨機動態(tài)飄落,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-02-02JavaScript實現(xiàn)隨機數(shù)生成器(去重)
這篇文章主要為大家詳細介紹了JavaScript實現(xiàn)隨機數(shù)生成器,生成不重復的隨機數(shù),具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-10-10