2013-04-24 45 views
0

这里是我的代码,到目前为止,jQuery的,垂直滑动文本只是熄灭屏幕而不盘旋回

function richardsSuperAmazingVerticalTextScroller(){ 


     $('#honor-roll ul').animate(
     { 
      top: '-=' + $('#honor-roll ul li:last').height() 
     }, 
     1000, 
     'linear', 
     function(){ 
      var offset = $('#honor-roll ul li:last').offset().top;     
      console.log(offset); 
      if(offset <= 640){ 
       $('#honor-roll ul li').css("margin", 0); 
       $('#honor-roll ul li:last').after($('#honor-roll ul li:first').detach()); 
      } 
     } 
    ); 
    } 
    $(document).ready(function(){ 
     setInterval('richardsSuperAmazingVerticalTextScroller()',1000) 
    }); 

上的jsfiddle它完美的作品,但在这个版本中失败的话,http://barkins.com/test.html

这里是小提琴上的相同码,http://jsfiddle.net/qmFD3/6/

任何人都可以发现问题吗?谢谢

回答

2

所以,它不是相同的代码。特别是,你的jsfiddle有

if(offset <= 640){ 
    $('#honor-roll ul').css("top", 0); 
    $('#honor-roll ul li:last').after($('#honor-roll ul li:first').detach()); 
} 

在您网站上的代码有

if(offset <= 640){ 
    $('#honor-roll ul li').css("margin", 0); 
    $('#honor-roll ul li:last').after($('#honor-roll ul li:first').detach()); 
} 

改变这种解决问题。

请注意,您不应该在setTimeout中使用字符串。你可以将其更改为只:

setInterval(richardsSuperAmazingVerticalTextScroller,1000) 
+0

我对网站进行了更新,但仍然存在相同的问题。以下是更新后的版本,http://barkins.com/test.html – Richard 2013-04-24 15:04:32

+0

您使用的是不同版本的jQuery。你为什么不使用1.9.1? – 2013-04-24 15:37:41

+0

宾果!不幸的是,我将代码插入的CMS内置了旧版本的jQuery。我需要尝试插入更新的版本,并查看它是否工作,同时指向两个版本的jQuery。谢谢! – Richard 2013-04-24 15:45:54

0

也许it's所有关于把

<script> 

身体元素内

+0

不是。这没有什么区别。 – 2013-04-24 14:57:36

+0

youre绝对正确 – 2013-04-24 15:02:57

1

你需要改变:

$('#honor-roll ul li').css("top", 0); 

到:

$('#honor-roll ul').css("top", 0); // Note the li 

以及包装所有jQuery代码内$(document).ready(function() { });

$(document).ready(function(){ 
    $('#honor-roll ul').css({display:"none"}); 
    $('#honor-roll ul').fadeIn('slow'); 
    setInterval(richardsSuperAmazingVerticalTextScroller,1000) 
}); 

编辑:

我想我知道为什么你的代码不能正常工作的原因,这是因为你的jQuery版本

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript"></script> 

这里是FIDDLE tha t与你的网站有完全相同的问题

所以你只需要使用另一个jQuery版本到你的网站,它应该工作。

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script> 
+0

谢谢你做出了这些修改,但仍然有问题,http://barkins.com/test.html – Richard 2013-04-24 15:31:05

+0

@Richard你的css在小提琴和你的网站是不一样的和你的jQuery版本。 – Eli 2013-04-24 15:33:26

+0

作出了改变,以及仍然无法正常工作,http://barkins.com/test.html – Richard 2013-04-24 15:37:37