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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.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 el.style.fontSize=这个; el.style.zIndex=这个; el.style.width=此值。_maxSize+‘px’; el.style.textAlign='center'; el.style.overflow='hidde_Javascript_Jquery - Fatal编程技术网

Javascript el.style.fontSize=这个; el.style.zIndex=这个; el.style.width=此值。_maxSize+‘px’; el.style.textAlign='center'; el.style.overflow='hidde

Javascript el.style.fontSize=这个; el.style.zIndex=这个; el.style.width=此值。_maxSize+‘px’; el.style.textAlign='center'; el.style.overflow='hidde,javascript,jquery,Javascript,Jquery,el.style.fontSize=这个; el.style.zIndex=这个; el.style.width=此值。_maxSize+‘px’; el.style.textAlign='center'; el.style.overflow='hidden'; el.innerHTML='●;'; } el.style.left=x+‘px’; el.style.top=y+‘px’; el.style.color=颜色; el.data={ x:x, y:y, dx:Math.c

el.style.fontSize=这个; el.style.zIndex=这个; el.style.width=此值。_maxSize+‘px’; el.style.textAlign='center'; el.style.overflow='hidden'; el.innerHTML='●;'; } el.style.left=x+‘px’; el.style.top=y+‘px’; el.style.color=颜色; el.data={ x:x, y:y, dx:Math.cos(rot)*速度+dx, 数学。罪恶(堕落)*速度+dy, 颜色:颜色, 年龄:Math.random()*.25 }; 如果(!foundEl){ document.getElementsByTagName('body')[0].appendChild(el); 这是粒子推动(el); } }, //移动现有粒子 _移动:函数(){ requestAnimFrame(此.\u animFn); //计算移动系数 var dif=this.\u time()-this.\u lastInterval; 这个。_lastInterval=这个。_time(); var delta=dif/20, 埃尔, D p=这个, r=数学功率(此电阻,δ), g=这个._重力*delta, a=dif/这个; 对于(变量i=0,l=p.length;i1) 继续; d、 年龄+=a; d、 dy+=g; d、 dx*=r; d、 dy*=r; d、 x+=d.dx*delta; d、 y+=d.dy*delta; 如果(d.x<0){ d、 dx*=-1; d、 x=0; } 否则,如果(d.x>此._车身宽度){ d、 dx*=-1; d、 x=此值。\u车身宽度; } 如果(d.y<0){ d、 dy*=-1; d、 y=0; } 否则,如果(d.y>此。\车身高度){ d、 dy*=-1; d、 y=这个。_车身高度; } 如果(d.年龄>1) d、 x=d.y=0; el.style.left=d.x+‘px’; el.style.top=d.y+‘px’; el.style.color=(Math.random()*.5+d.age>=1)?“透明”:d.color; el.style.fontSize=Math.max(this._minSize,(1-d.age)*this._maxSize)+px'; } }, //计算所有粒子的新位置 调整大小:函数(){ //获得新的宽度和高度 this.\u bodyWidth=this.\u getWindowWidth()-this.\u maxSize; this.\u bodyHeight=this.\u getWindowHeight()-this.\u maxSize-10; }, //获取窗口宽度 _getWindowWidth:函数(){ 返回文档.getElementsByTagName('body')[0].offsetWidth; }, //获取窗口高度 _getWindowHeight:函数(){ var h=Math.max(self.innerHeight | 0,window.innerHeight | 0); if(document.documentElement) h=Math.max(h,document.documentElement.clientHeight | | 0); if(document.body){ h=Math.max(h,document.body.clientHeight | | 0); h=数学.max(h,document.body.scrollHeight | | 0); h=数学.max(h,document.body.offsetHeight | | 0); } 返回h; } }; //使用setTimeout回退填充层 window.requestAnimFrame=(函数(){ return window.requestAnimationFrame|| window.webkitRequestAnimationFrame|| window.mozRequestAnimationFrame|| window.oRequestAnimationFrame|| window.msRequestAnimationFrame|| 功能(cb){ 设置超时(cb,1000/60); }; })(); 函数stopFireworks(){ 烟花。停止(); } 烟花。开始()

停止

请将您的问题精简为a,并更详细地解释您的问题。307行代码太多了。@CertainPerformance我发布了整个函数,以便您可以看到我创建的函数类型。问题在于:fireforks.start(),如何再次终止此函数。您的编辑不会使其成为一个错误。请阅读如何创建它。另外,请编辑您的标题以总结您的问题。我猜您正在寻找一种方法来终止导致烟花显示的事件循环。没有办法终止函数。您应该发布
firework.end
firework.start
的代码,这样我们就可以帮助解决问题。从您的原始代码来看,它看起来像是
\u addExplosion
调用自身-因此您可以添加一个函数
end
,该函数将布尔值设置为false,并且仅当该布尔值为true时,will
\u addExplosion
会再次调用自己。到目前为止,您建议的解决方案非常好,但还没有完成焰火。我不想为它创建一个按钮,我不想让玩家知道它。我尝试了这个变体,但不幸的是它不起作用:
Start
这个想法是,Start按钮也被用作停止焰火的功能。即使使用stop按钮,我也无法停止焰火。你知道为什么会这样吗?@sharete你有没有试着在这么短的时间内运行这个代码段?我为自己工作——有时会发生额外的爆炸,什么的
fireworks.start(); //Start the fireworks.
stop: function() {
    this._running = false;
    window.clearTimeout();
    for (var i = 0; i < this._particles.length; i++) {
        this._particles[i].parentNode.removeChild(this._particles[i]);
    }
},
if (this._running) {
    window.setTimeout(function () { return fireworks._addExplosion.apply(fireworks); },
            this._random(this._interval[1] - this._interval[0]) + this._interval[0]);
}
function stopFireworks() {
    fireworks.stop();
}
<button onclick="stopFireworks()">Stop</button>