您的位置:首页 > Web前端 > JQuery

jquery滚动效果-无间隙向上滚动

2016-05-27 15:06 417 查看
第一:html页面

<div class="global_module news">
<h3>最新动态<img src="images/down.png" /></h3>
<div class="scrollNews">
<ul id="newsScr">
<!--动态生成,减少工作量,操作简单方便-->
</ul>
</div>

</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);
});
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息