作者:微博网友_02887414 | 来源:互联网 | 2020-09-10 22:29
代码
引入MyTools.js库
1.html
<
>
2.css
*{margin: 0;padding: 0;}
a{
color: #999;
text-decoration: none;
position: absolute;
top: 50%;
transform: translateY(-50%);
background-color: rgba(0, 0, 0, .4);
}
a:hover{
color: #f8b62b;
}
i{
font-size: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
#box{
height: 482px;
width: 830px;
background-color: red;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
overflow: hidden;
}
#box_content{
height: 100%;
width: 100%;
cursor: pointer;
}
#box_content img{
position: absolute;
vertical-align: top;
height: 100%;
width: 100%;
/*left: 830px;*/
}
.box_img{
width: 100%;
height: 100%;
position: absolute;}
.box_control_right{
position: absolute;
right: 0;
}
.box_control_left{
position: absolute;
left: 0;
}
ul{
position: absolute;
bottom: 30px;
left: 50%;
transform: translateX(-50%);
display: flex;
justify-content:space-evenly;
}
ul>li{
list-style: none;
width: 16px;
height: 16px;
background-color: #fff;
margin: 0 3px;
border-radius: 50%;
cursor: pointer;
}
ul>li.current{
background-color: darkorange;
}
3.js
window.addEventListener(&#39;load&#39;,function (ev) {
// 轮播图
(function () {
// 1. 获取需要标签
var boxCOntent= myTool.$(&#39;box_content&#39;);
var cOntentImg= boxContent.children;
var boxCOntrol= myTool.$(&#39;box_control&#39;);
var cOntrolBottom= boxControl.children[2];
// 2. 全局索引
var iNow = 0;
// 3. 根据图片个数动态添加下方图片指示器
for (var i = 0; i iNow){
myTool.slowMoving(contentImg[iNow],{&#39;left&#39;:-scrollImgWidth},null);
contentImg[index].style.left = scrollImgWidth + &#39;px&#39;;
}else if(index = contentImg.length) {
iNow = 0;
}
contentImg[iNow].style.left = scrollImgWidth + &#39;px&#39;;
myTool.slowMoving(contentImg[iNow], {"left": 0},null);
// 切换索引
changeIndex();
}
// 8. 设置定时器
var timerId = setInterval(autoPlay,2000);
// 9. 鼠标进入图片p后设置和清除定时器
myTool.$(&#39;box&#39;).addEventListener(&#39;mouseover&#39;,function () {
clearInterval(timerId);
});
myTool.$(&#39;box&#39;).addEventListener(&#39;mouseout&#39;,function () {
timerId = setInterval(autoPlay,2000);
});
})();
},false);
更多js特效,请移步js特效下载栏目。
以上就是JS怎么实现简单轮播图特效?(图文详解)的详细内容,更多请关注 第一PHP社区 其它相关文章!