上下滚动实现
来源:互联网 发布:ui设计师与美工的区别 编辑:程序博客网 时间:2024/05/20 11:34
<style>
body, ul, li, p {
padding: 0;
margin: 0;
}
ul, li {
list-style: none;
}
.main-wrap {
margin-top: 50px;
width: 100%;
}
.scroll-wrap {
width: 500px;
height: 300px;
margin: 0px auto;
overflow: hidden;
position: relative;
}
.scroll-show-wrap {
width: 500px;
height: 300px;
overflow: hidden;
}
.scroll-show1 {
width: 500px;
height: 300px;
background-color: red;
}
.scroll-show2 {
width: 500px;
height: 300px;
background-color: gold;
}
.scroll-show3 {
width: 500px;
height: 300px;
background-color: green;
}
.scroll-item-warp{
position: absolute;
bottom: 20px;
right: 20px;
}
.scroll-item-warp ul li{
float:left;
width: 30px;
height: 30px;
background-color: #31b0d5;
color: white;
font-weight: 600;
text-align: center;
margin-right: 5px;
border: 1px solid #808080;
cursor: pointer;
}
</style>
</head>
<body>
<div class="main-wrap">
<div class="scroll-wrap">
<div class="scroll-show-wrap">
<div class="scroll-show1"></div>
<div class="scroll-show2"></div>
<div class="scroll-show3"></div>
</div>
<div class="scroll-item-warp">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</div>
</div>
</div>
<script src="../js/libs/jquery-1.11.3.js">
</script>
<script>
var height = $(".scroll-wrap").height();
/* var scrollMaxHeight = ($(".scroll-item-warp ul li").length-1)*height;*/
//也可以
var scrollMaxHeight = $(".scroll-show-wrap").get(0).scrollHeight-$(".scroll-show-wrap").get(0).clientHeight;
$(".scroll-item-warp ul li").first().css({"background-color":"#C27310"});
//定时
setInterval("scrollFun()",3000);
var scrollFun = function () {
$(".scroll-item-warp ul li").css({"background-color":"#31b0d5"});
var currentScrollTop = $(".scroll-show-wrap").get(0).scrollTop;
if( $(".scroll-show-wrap").get(0).scrollTop >= scrollMaxHeight){
$(".scroll-item-warp ul li").eq(0).css({"background-color":"#C27310"});
$(".scroll-show-wrap").animate({
"scrollTop":0
});
}else{
var index = currentScrollTop/height+1;
$(".scroll-item-warp ul li").eq(index).css({"background-color":"#C27310"});
$(".scroll-show-wrap").animate({
"scrollTop":'+='+height
});
}
};
$("li").click(function () {
var index = $(".scroll-item-warp ul li").index($(this));
$(".scroll-item-warp ul li").css({"background-color":"#31b0d5"});
$(this).css({"background-color":"#C27310"});
var scrollTop = index*height;
$(".scroll-show-wrap").animate({
"scrollTop":scrollTop
});
});
- jquery 实现上下滚动
- 上下滚动实现
- android实现左右上下滚动
- 实现上下滚动的TextView
- 实现上下滚动的TextView
- 实现上下滚动的TextView
- JavaScript实现新闻上下滚动
- Android 实现上下滚动TextSwitcher
- QT 实现字幕滚动(上下滚动)
- JS实现文本内容上下滚动效果
- 用JavaScript实现上下文字滚动特效
- js实现文字定时上下滚动效果
- 实现TextView文本的上下滚动
- jquery实现文字的上下滚动效果
- jquery实现:页面上下滚动效果
- 实现jqgrid表格数据上下滚动
- iOS文字上下滚动效果的实现
- 图+文上下滚动跑马灯实现
- 苹果在法国设立图像技术研发实验室
- jq.js 获取 各个
- HomeBrew
- Three ways to create Java thread
- Java命令注入之防护
- 上下滚动实现
- NULL和空是两个概念的原因
- 英汉互译
- Java生成excel表格
- 鲜为人知的编程真相
- C#常用集合的使用
- dpkg命令的用法
- Linux系统中校验下载文件的完整性方法(MD5,SHA1,PGP)
- ruby