Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/416.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery和JS中的停止计时器_Javascript_Jquery - Fatal编程技术网

Javascript jQuery和JS中的停止计时器

Javascript jQuery和JS中的停止计时器,javascript,jquery,Javascript,Jquery,当弹出窗口激活时,我需要停止计时器 我有两个弹出窗口。但它不适用于第一个,当页面打开时,第一个是自动的 // Calling function - this is in popup.html var popUp1 = false; var popUp2 = false; // Calling function with instruction by click function togglePopup(){ popUp1 = document.getElementById("po

当弹出窗口激活时,我需要停止计时器

我有两个弹出窗口。但它不适用于第一个,当页面打开时,第一个是自动的

// Calling function - this is in popup.html
var popUp1 = false;
var popUp2 = false;

// Calling function with instruction by click
function togglePopup(){
  popUp1 = document.getElementById("popup-1").classList.toggle("active");
  timeToggle()
}

// Calling function with description by click
function myFunction(){
  popUp2 = document.getElementById("desc").classList.toggle("activeD");
  timeToggle()
}

// function for pausing game when there is popUp
function timeToggle(){
  if (!popUp1 && !popUp2){
    Init();
  }else{
    clearInterval(moveItIntervalID); //stopping time and random images
    clearInterval(timeIntervalID);
  }
}

//here is funcion with automatic popup
    $( document ).ready(function() { 
        $('#descS').bPopup();
        timeToggle()

(function(c){c.fn.bPopup=function(A,E){function L(){a.contentContainer=c(a.contentContainer||b);switch(a.content){case "iframe":var d=c('<iframe class="b-iframe" '+a.iframeAttr+"></iframe>");d.appendTo(a.contentContainer);t=b.outerHeight(!0);u=b.outerWidth(!0);B();d.attr("src",a.loadUrl);l(a.loadCallback);break;case "image":B();c("<img />").load(function(){l(a.loadCallback);F(c(this))}).attr("src",a.loadUrl).hide().appendTo(a.contentContainer);break;default:B(),c('<div class="b-ajax-wrapper"></div>').load(a.loadUrl,a.loadData,function(d,b,e){l(a.loadCallback,b);F(c(this))}).hide().appendTo(a.contentContainer)}}function B(){a.modal&&c('<div class="b-modal '+e+'"></div>').css({backgroundColor:a.modalColor,position:"fixed",top:0,right:0,bottom:0,left:0,opacity:0,zIndex:a.zIndex+v}).appendTo(a.appendTo).fadeTo(a.speed,a.opacity);C();b.data("bPopup",a).data("id",e).css({left:"slideIn"==a.transition||"slideBack"==a.transition?"slideBack"==a.transition?f.scrollLeft()+w:-1*(x+u):m(!(!a.follow[0]&&n||g)),position:a.positionStyle||"absolute",top:"slideDown"==a.transition||"slideUp"==a.transition?"slideUp"==a.transition?f.scrollTop()+y:z+-1*t:p(!(!a.follow[1]&&q||g)),"z-index":a.zIndex+v+1}).each(function(){a.appending&&c(this).appendTo(a.appendTo)});G(!0)}function r(){a.modal&&c(".b-modal."+b.data("id")).fadeTo(a.speed,0,function(){c(this).remove()});a.scrollBar||c("html").css("overflow","auto");c(".b-modal."+e).unbind("click");f.unbind("keydown."+e);k.unbind("."+e).data("bPopup",0<k.data("bPopup")-1?k.data("bPopup")-1:null);b.undelegate(".bClose, ."+a.closeClass,"click."+e,r).data("bPopup",null);clearTimeout(H);G();return!1}function I(d){y=k.height();w=k.width();h=D();if(h.x||h.y)clearTimeout(J),J=setTimeout(function(){C();d=d||a.followSpeed;var e={};h.x&&(e.left=a.follow[0]?m(!0):"auto");h.y&&(e.top=a.follow[1]?p(!0):"auto");b.dequeue().each(function(){g?c(this).css({left:x,top:z}):c(this).animate(e,d,a.followEasing)})},50)}function F(d){var c=d.width(),e=d.height(),f={};a.contentContainer.css({height:e,width:c});e>=b.height()&&(f.height=b.height());c>=b.width()&&(f.width=b.width());t=b.outerHeight(!0);u=b.outerWidth(!0);C();a.contentContainer.css({height:"auto",width:"auto"});f.left=m(!(!a.follow[0]&&n||g));f.top=p(!(!a.follow[1]&&q||g));b.animate(f,250,function(){d.show();h=D()})}function M(){k.data("bPopup",v);b.delegate(".bClose, ."+a.closeClass,"click."+e,r);a.modalClose&&c(".b-modal."+e).css("cursor","pointer").bind("click",r);N||!a.follow[0]&&!a.follow[1]||k.bind("scroll."+e,function(){if(h.x||h.y){var d={};h.x&&(d.left=a.follow[0]?m(!g):"auto");h.y&&(d.top=a.follow[1]?p(!g):"auto");b.dequeue().animate(d,a.followSpeed,a.followEasing)}}).bind("resize."+e,function(){I()});a.escClose&&f.bind("keydown."+e,function(a){27==a.which&&r()})}function G(d){function c(e){b.css({display:"block",opacity:1}).animate(e,a.speed,a.easing,function(){K(d)})}switch(d?a.transition:a.transitionClose||a.transition){case "slideIn":c({left:d?m(!(!a.follow[0]&&n||g)):f.scrollLeft()-(u||b.outerWidth(!0))-200});break;case "slideBack":c({left:d?m(!(!a.follow[0]&&n||g)):f.scrollLeft()+w+200});break;case "slideDown":c({top:d?p(!(!a.follow[1]&&q||g)):f.scrollTop()-(t||b.outerHeight(!0))-200});break;case "slideUp":c({top:d?p(!(!a.follow[1]&&q||g)):f.scrollTop()+y+200});break;default:b.stop().fadeTo(a.speed,d?1:0,function(){K(d)})}}function K(d){d?(M(),l(E),a.autoClose&&(H=setTimeout(r,a.autoClose))):(b.hide(),l(a.onClose),a.loadUrl&&(a.contentContainer.empty(),b.css({height:"auto",width:"auto"})))}function m(a){return a?x+f.scrollLeft():x}function p(a){return a?z+f.scrollTop():z}function l(a,e){c.isFunction(a)&&a.call(b,e)}function C(){z=q?a.position[1]:Math.max(0,(y-b.outerHeight(!0))/2-a.amsl);x=n?a.position[0]:(w-b.outerWidth(!0))/2;h=D()}function D(){return{x:w>b.outerWidth(!0),y:y>b.outerHeight(!0)}}c.isFunction(A)&&(E=A,A=null);var a=c.extend({},c.fn.bPopup.defaults,A);a.scrollBar||c("html").css("overflow","hidden");var b=this,f=c(document),k=c(window),y=k.height(),w=k.width(),N=/OS 6(_\d)+/i.test(navigator.userAgent),v=0,e,h,q,n,g,z,x,t,u,J,H;b.close=function(){r()};b.reposition=function(a){I(a)};return b.each(function(){c(this).data("bPopup")||(l(a.onOpen),v=(k.data("bPopup")||0)+1,e="__b-popup"+v+"__",q="auto"!==a.position[1],n="auto"!==a.position[0],g="fixed"===a.positionStyle,t=b.outerHeight(!0),u=b.outerWidth(!0),a.loadUrl?L():B())})};c.fn.bPopup.defaults={amsl:50,appending:!0,appendTo:"body",autoClose:!1,closeClass:"b-close",content:"ajax",contentContainer:!1,easing:"swing",escClose:!0,follow:[!0,!0],followEasing:"swing",followSpeed:500,iframeAttr:'scrolling="no" frameborder="0"',loadCallback:!1,loadData:!1,loadUrl:!1,modal:!0,modalClose:!0,modalColor:"#000",onClose:!1,onOpen:!1,opacity:.7,position:["auto","auto"],positionStyle:"absolute",scrollBar:!0,speed:250,transition:"fadeIn",transitionClose:!1,zIndex:9997}})(jQuery);

function Init(){
//set interval of moving image in case the user will not click it
    moveItIntervalID = setInterval(moveIt, intervalTimeout);
    timeIntervalID = setInterval(countDown, 1000);```
//调用函数-这在popup.html中
var popUp1=假;
var popUp2=假;
//通过单击调用带指令的函数
函数togglePopup(){
popUp1=document.getElementById(“popup-1”).classList.toggle(“active”);
时间切换()
}
//通过单击调用具有描述的函数
函数myFunction(){
popUp2=document.getElementById(“desc”).classList.toggle(“activeD”);
时间切换()
}
//有弹出窗口时暂停游戏的功能
函数timeToggle(){
如果(!popUp1&&!popUp2){
Init();
}否则{
clearInterval(moveItIntervalID);//停止时间和随机图像
clearInterval(timeIntervalID);
}
}
//这是带有自动弹出窗口的函数
$(文档).ready(函数(){
$('#descS').bPopup();
时间切换()
(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(E(f,250,f,250,函数(函数)的(函数)的(函数)的(函数)的(函数)的(函数)的(函数)的(函数)的(函数)的)M)函数的(函数)的(函数)的(函数)的(函数)的(函数)的(函数)的)M)函数的(函数)的)M)函数的(函数)M)函数的(函数)的(函数)M)的(数据(数据(k.数据(数据)数据(b.数据(BPopopopopopopopop,v),v),v),v;b)的;b)代表(b.b.代表(b.代表(b.b.代表(b.b.b.代表(b.b.b.代表(b.b.b.b.b.代表(b.b.b.b.b.b.代表(b.b.b.代表(如如如如如如如“失去,,,,,,,,,“.b.b.b.d.top=a.follow[1]?p(!g):“自动”)b.dequeue().animate(d,a.followSpeed,a.followsing)}}.bind(“resize.”+e,function(){I()});a.esclose和f.bind(“keydown.”+e,function(a){27==a.which&&r()}}函数G(d){函数c(e){b.css({display:“block”,不透明:1})。animate(e,a.speed,a.easing,a.easing,function(){K(d)})开关(d?a.transition!(a)下面下面(0)跟(0)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)和(n)的)和(n)和(n)和(n)的)的!(!a.follow[1]&&q | | g)):f.scrollTop()+y+200});break;默认值:b.stop().fadeTo(a.speed,d?1:0,function(){K(d)}}函数K(d){d?(M(),l(E),a.autoClose&&&(H=setTimeout(r,a.autoClose)):(b.hide(),l(a.onClose),a.loadUrl&(a.contentContainer.empty(),b.css({高度:“auto”,宽度:“auto”})))函数M(a){返回a?x+f.scrollLeft():x}函数p(a){返回a?z+f.scroll(),调用函数l(c)}c)}(2)a.amsl;x=n?a.a.a.a.位置[0]:::(w-b.b.b.Othethethethethethethethethethethethethea.a.位置[0]:(w-b.Othethewwb.OthetheWithWith(0)位置[1]::数学。数学。最大(0,(y-b.b.b.b.b.Othethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethetheat(0)(0)(0)0)0)0)0)0)0)0)0;x;x;x=x=n)x=n?a.a.a.a.a.a.位置[0)位置[0::::::::::::::::::::::(窗),y=k.高度()6.测试(Navi者.用户代理),v=0,e,h,h,q,N,g,z,z,x,N,g,z,x,t,t,g,g,z,z,x,x,t,u,J,h,h;b.关闭(k)k.宽度(),N,N,N,h;b.关闭(b.关闭)功能(r(),r();b.重新定位(b.重新定位=函数(a)(a)(a)(a)(a)(a)(a)(i(a)(a)(a)(i(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(c)(函数)(c)(c)(c)(c)(c)(c)(c)(这)这)这个数据(BPOPOPOPOPOPOPUP)数据)数据(a(a(a)(a)(英国邮政管理公司)的)本次开放开放)的)本币)本币(a(a)本币)本币)本币=a.positionStyle,t=b.outerHeight(!0),u=b.outerWidth(!0),a.loadUrl?L():b())};c.fn.bPopup.defaults={amsl:50,appendTo:!0,appendTo:!body,autoClose:!1,closeClass:“b-close”,content:“ajax”,contentContainer:!1,easing:“swing”,esclose:!0,following:[!0,!0],following:,followSpeed:500,iframeAttr:'scrolling=“no”frameborder=“0”,loadCallback:!1,loadData:!1,loadUrl:!1,模态:!0,模态Close:!0,模态颜色:“#000”,onClose:!1,onOpen:!1,不透明度:!7,位置:[“自动”,“自动”],位置样式:“绝对”,滚动条:!0,速度:250,转换:“fadeIn”,转换Close:!1,zIndex:9997})(jQuery);
函数Init(){
//设置移动图像的间隔,以防用户不点击它
moveItIntervalID=setInterval(moveIt,intervalTimeout);
timeIntervalID=setInterval(倒计时,1000)```

嗯,它不起作用,因为您甚至没有调用函数。在docready上,使用您自己的函数之一打开弹出窗口,或者调用
timeToggle()
。当我像这样调用函数时:
JavaScript$(document).ready(function(){$('#descS')。bPopup();timeToggle())
发生了一些奇怪的事情-时间变快了O.O可能是因为你设置了两次计时器。
Init()
do做什么?它的一部分:
JavaScript函数Init(){//set运动图像的间隔,以防用户不点击它moveItIntervalID=setInterval(moveIt,intervalTimeout);timeIntervalID=setInterval(倒计时,1000);
注意,在现代HTML中,script元素支持
defer
属性(甚至IE11也支持该属性),它告诉浏览器“无论何时”加载脚本,但只在DOM完成后运行脚本,因此使用
defer
加载jquery和您自己的脚本,您不再需要
$(文档)。准备好了吗(function(){
现在,jQuery在web上已经很老了:普通的JS在很多方面都赶上并超越了它。