JS实现大图滚动、无缝连接
来源:互联网 发布:马蓉起诉王宝强 知乎 编辑:程序博客网 时间:2024/06/05 07:38
大图滚动2
*{
margin:0;
padding:0;
}
#outer{
width: 1000px;
height: 500px;
margin:100px auto;
overflow: hidden;
position: relative;
}
#inner{
height: 500px;
position: absolute;
top:0px;
/left:0px;/
/transition: all 0.5s;/
}
#inner img{
width: 1000px;
height: 500px;
float:left;
}
#btn_box{
position: absolute;
list-style-type: none;
width: 100%;
left:0;
bottom:30px;
text-align: center;
}
#btn_box li{
display: inline-block;
height: 30px;
width: 30px;
border-radius: 50%;
background-color: #fff;
font-size: 20px;
line-height: 30px;
}
#btn_box li.active{
color:#fff;
background-color:red;
}
#prevBtn,
#nextBtn{
width: 50px;
height: 100px;
position: absolute;
top:200px;
background-color: rgba(0,0,0,.5);
font-size: 30px;
text-align: center;
line-height: 100px;
opacity:0;
transition: all 1.5s;
}
#prevBtn{
left:0px;
}
#nextBtn{
right:0px;
}
<img src="../img/01.jpg"> <img src="../img/02.jpg"> <img src="../img/03.jpg"> <img src="../img/04.jpg"> <img src="../img/05.jpg"> <img src="../img/06.jpg"> <img src="../img/01.jpg"> </div> <ul id="btn_box"> <li class="active">1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> <li>6</li> </ul> <div id="prevBtn"><</div> <div id="nextBtn">></div></div><script src="../tween.js"></script><script> var outer = document.getElementById('outer'); var inner = document.getElementById('inner'); var imgs = inner.getElementsByTagName('img'); var btn_box = document.getElementById('btn_box'); var btns = btn_box.getElementsByTagName('li'); var prevBtn = document.getElementById('prevBtn'); var nextBtn = document.getElementById('nextBtn'); var pieceWidth = imgs[0].offsetWidth; inner.style.width = imgs.length*pieceWidth + 'px'; var index = 0; var contorl = true;//定义一个布尔值,用来控制切换的时机(图片在滚动过程中是禁止切换) var time = null;//图片自动轮播计时器 var time1 = null;//图片滑动计时器 function tab(){ if(index >= imgs.length){ index = 1; inner.style.left = 0; } if(index < 0){ index = btns.length - 1; inner.style.left = -pieceWidth*(imgs.length-1) +'px'; } var t = 0; var maxT = 100; var start = inner.offsetLeft; var end = -pieceWidth*index; var change = end - start; clearInterval(time1); time1 = setInterval(function(){ t++; if(t >= maxT){ clearInterval(time1); contorl = true; } // inner.style.left = change/maxT*t + start + 'px'; inner.style.left = Tween.Quart.easeOut(t,start,change,maxT) + 'px'; },10); // inner.style.left = -pieceWidth*index + 'px'; for(var i=0; i<btns.length; i++){ btns[i].className = ''; } if(index == btns.length){ btns[0].className = 'active'; }else{ btns[index].className = 'active'; } } function next(){ index++; tab(); } function prev(){ index--; tab(); } time = setInterval(next,3000); for(var i=0; i<btns.length; i++){ btns[i].index = i; btns[i].onclick = function(){ if(contorl){ clearInterval(time); if(this.index == 0 && index == btns.length){ index = btns.length; }else{ index = this.index; } tab(); time = setInterval(next,3000) } contorl = false; } } outer.onmouseover = function(){ prevBtn.style.opacity = 1; nextBtn.style.opacity = 1; } outer.onmouseout = function(){ prevBtn.style.opacity = 0; nextBtn.style.opacity = 0; } prevBtn.onclick = function(){ if(contorl){ clearInterval(time); prev(); time = setInterval(next,3000); } contorl = false; } nextBtn.onclick = function(){ if(contorl){ clearInterval(time); next(); time = setInterval(next,3000); } contorl = false; }</script>
- JS实现大图滚动、无缝连接
- js大图匀速无缝滚动效果
- js实现无缝滚动
- JS实现无缝滚动
- js实现无缝滚动
- JS实现图片无缝滚动
- 通过js实现无缝滚动
- js实现无缝滚动效果
- js 实现图片无缝滚动
- js实现标准无缝滚动
- 原生js实现无缝滚动
- JS实现文字无缝滚动
- 原声js实现无缝滚动
- JS实现横向图片无缝滚动
- js 实现无缝滚动 兼容IE FF
- 无缝滚动效果 js可以实现
- js实现marquee头尾无缝滚动
- js实现图片的无缝滚动
- linux命令rm
- vue-cli搭建项目
- IOS 返回根视图
- 深入浅出Spring(一) 代理模式(静态代理,jdkproxy,cglib)
- linux下oracle迁移
- JS实现大图滚动、无缝连接
- Shader编程学习笔记(二)—— Shader和渲染管线
- yum安装软件提示 cannot find a valid baseurl for repo:base/7/x86_64
- KAFKA-生产者、消息费java开发示例
- Oracle 11g安装教程
- 转载vultr搭载Shadowsocks
- Android调式工具 --Facebook Stetho --无需root手机设备即可查看data目录下数据
- 学习小得-201704
- 裴波那契数列的实现