对setInterval在火狐和chrome切换标签产生奇怪的效果之探索,与解决方案!

在上一篇文章: 觉得猪八戒网左下角的文字滚动,效果不错,自己摸索了一下,以自己的方法实现了!

  就有这种效果,不过影响不大。Demo的影响就大了!

  网上也有人出现过这样的问题看下面的帖子地址:

  firefox 6下 setInterval的一个问题

  讨论的人很多,但没给出答案来。

  怎么想都想不明白!

  今天,突然茅塞顿开,可能是线程的概念,但是具体原因还是不明白,希望有人了解其原应告知,非常感激!

  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(),

  //灰块运动函数

  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运动完后,我再回调move()函数。

  });

  });

  });

  };

  move();

  // 红块运动函数

  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);

  // 红块运动函数

  })();