第一:html页面
- <div class="global_module news">
- <h3>最新动态<img src="images/down.png" /></h3>
- <div class="scrollNews">
- <ul id="newsScr">
- <!--动态生成,减少工作量,操作简单方便-->
- </ul>
- </div>
- lt;/div>
数据向上滚动
第二:css样式
- .global_module h3{
- background:#3b5998;
- color:#FFFFFF;
- padding-left:10px;
- margin: 0;
- height:25px;
- padding-top:6px;
- font-size:14px;
- }
- .global_module h3 img{
- float:right;
- }
- .scrollNews{
- height:200px;
- overflow: hidden;
- }
- .scrollNews ul li{
- height:26px;
- line-height:26px;
- }
第三:js文件
- $(function(){
- //数据进行滚动
- var $this=$('.scrollNews');
- var scrollTimer=setInterval(function(){
- scrollNews($this);
- },1000);
- $this.hover(function(){
- clearInterval(scrollTimer);
- },function(){
- scrollTimer=setInterval(function(){
- scrollNews($this);
- },1000);
- });
- });
- function scrollNews(obj){
- var $self=obj.find('ul:first');
- var lineHeight=$self.find('li:first').height();
- $self.animate({
- 'marginTop':-lineHeight+'px'
- },600,function(){
- $self.css({marginTop:0}).find('li:first').appendTo($self);
- });
- }