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);
});
}
<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);
});
}
相关文章推荐
- JQuery1——基础($对象,选择器,对象转换)
- Extjs4.0 最新最全视频教程
- Javascript中toFixed方法的改进
- Web布局连载——两栏固定布局(五)
- JavaScript演示排序算法
- 2015-2016网页设计趋势分析 Web Design of Trends
- 5个常见可用性错误和解决方案
- jQuery Ajax 跨域调用
- 移动端的长按事件
- jquery教程靠边站,一分钱不花让你免费学会jquery
- JQuery+Strusts1.x无刷新登录
- [div+css]晒晒最新制作专题推广页模板
- 在Windows 8.1的IE 11中屏蔽双击放大功能
- 盒子模型
- CSS选择器
- CSS样式优先权
- js数组实现图片轮播
- $.ajax()方法详解
- jQuery ajax - ajax() 方法