>  기사  >  웹 프론트엔드  >  JavaScript는 페이지 무작동 카운트다운 종료를 구현합니다.

JavaScript는 페이지 무작동 카운트다운 종료를 구현합니다.

高洛峰
高洛峰원래의
2016-12-09 13:26:021401검색

프로젝트의 프런트엔드 페이지를 구현해야 합니다. 아무도 페이지를 운영하지 않으면 카운트다운에 들어갑니다. 다음은 프런트엔드 코드 구현입니다.

//设置(倒计时功能)开关
var _mouseActiveListener_flag = true;

beforecount: 트리거 카운트다운 간격(단위: 밀리초)

count: 총 카운트다운(단위: 초)

var mouseActiveListener = function (beforecount, count, callback) {
 //config
var __countdown_html = &#39;<div id="__tt" style="position:fixed;top:110px;right:10px;z-index:1000;color:#eee;font-size:25px;"></div>&#39;;
 //define
 var target = null, _t = null, _tc = null;
var target_countdown = function (__count) {
  if (__count >= 0) {
  target.innerHTML = __count + &#39;秒后退出&#39;;
  _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(&#39;click&#39;, function () {
  _t_clear();
  _t = _t_exec();
 });
 };

 

//后置操作,解释:在5秒后(5000)不操作的状态下触发倒计时,倒计时180秒,具体看View Code里面的函数。
mouseActiveListener(5000, 180, function () {
 window.location.href = "/Home/Index";
 });

 


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.