對setInterval在火狐和chrome切換標簽產(chǎn)生奇怪的效果之探索,與解決方案!
在上一篇文章: 覺得豬八戒網(wǎng)左下角的文字滾動,效果不錯,自己摸索了一下,以自己的方法實現(xiàn)了!
就有這種效果,不過影響不大。Demo的影響就大了!
網(wǎng)上也有人出現(xiàn)過這樣的問題看下面的帖子地址:
討論的人很多,但沒給出答案來。
怎么想都想不明白!
今天,突然茅塞頓開,可能是線程的概念,但是具體原因還是不明白,希望有人了解其原應(yīng)告知,非常感激!
Demo 中黑色的Div是不受瀏覽器標簽切換影響的
而紅色的Div會受到影響。
HTML:
<div id="move" style="position: absolute; width: 100px; height: 100px; top: 0pt; left: 0pt; background: none repeat scroll 0% 0% #000000; z-index: 999; color: #ffffff;">我不受瀏覽器標簽切換影響!Hoooo</div>
<div id="move2" style="position: absolute; width: 100px; height: 100px; top: 0pt; left: 0pt; background: none repeat scroll 0% 0% red; z-index: 999; color: #ffffff;">我受瀏覽器標簽切換影響!5555</div>
javascript:
(function(){
var elem = Meng.getId('move'),
elem2 = Meng.getId('move2'),
pos = Meng.getElemViewPosition(elem),
view = Meng.getBrowserView(),
//灰塊運動函數(shù)
move = function(){
var t1 = Meng.animate(elem,{top:0,left:0},{top:view.height-100,left:view.width-100},3000,function(){
var t2 = Meng.animate(elem,{left:view.width-100},{left:100-view.width},3000,function(){
var t3 = Meng.animate(elem,{top:view.height-100},{top:100-view.height},3000,function(){
move();//確定t3運動完后,我再回調(diào)move()函數(shù)。
});
});
});
};
move();
// 紅塊運動函數(shù)
Meng.setStyle(elem2,{top:0,left:(view.width-100)+'px'});
var move2 = function(){
var t1 = Meng.animate(elem2,{top:0,left:view.width-100},{top:view.height-100,left:100-view.width},3000,function(){
var t2 = Meng.animate(elem2,{top:view.height-100},{top:100-view.height},3000,function(){
var t3 = Meng.animate(elem2,{left:0},{left:view.width-100},3000,function(){
});
});
});
};
move2();
setInterval(function(){move2();},9050);
// 紅塊運動函數(shù)
})();
相關(guān)文章
antd-mobile ListView長列表的數(shù)據(jù)更新遇到的坑
這篇文章主要介紹了antd-mobile ListView長列表的數(shù)據(jù)更新遇到的坑,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-04-04js獲取RadioButtonList的Value/Text及選中值等信息實現(xiàn)代碼
RadioButtonList的Value,Text及選中值等信息想必有很多的朋友都想獲取到,接下來將為你介紹下如何使用js獲取,代碼很詳細,感興趣的你可以參考下,或許對你有所幫助2013-03-03類似php的js數(shù)組的in_array函數(shù)自定義方法
PHP的數(shù)組函數(shù)in_array()非常方便,下面就為大家介紹下自定義類似php的js數(shù)組的in_array函數(shù),具體實現(xiàn)方法如下,感興趣的朋友可以參考下2013-12-12bootstrap與pagehelper實現(xiàn)分頁效果
這篇文章主要為大家詳細介紹了bootstrap與pagehelper實現(xiàn)分頁效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-12-12