js实现轮播图效果 z-index实现轮播图
前端  /  管理员 发布于 7年前   214
本文实例为大家分享了js实现轮播图效果的具体代码,供大家参考,具体内容如下 实现轮播图 学习前端差不多两三个月,在这里记录分享一下。因本人菜鸟一枚,希望大佬们多多指点,勿喷。 通过计算每一张图片高度实现滑动轮播图 HTML代码: CSS代码: JS代码: 如有错误望指出。 利用z-index实现轮播图 CSS代码 JS代码 利用index来实现轮播,但是生硬。 结语 以上就是两种方法实现轮播图效果。 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。 122 在 123 在 原梓番博客 在 博主 在 1111 在
* { transition: all 1s; margin: 0px; padding: 0px;}.fate { position: absolute; top: 0%; width: 512px; height: 512px; overflow: hidden;}ul li { list-style: none;}.lancer{ position: absolute; top: 0%; width: 100%; height: 100%;}.saber { top: 0px; position: absolute;}.archer{ position: absolute;}button { z-index: 99;}
var index=0;function godown(){ var li = document.getElementsByTagName("li"); //获取单个li宽度(单张图片高度) var liHeight = li[0].scrollHeight; var goup=document.getElementsByClassName("goup"); var lancer=document.getElementsByClassName("lancer")[0]; if(index<4){ index++; }else{ index=0; } lancer.style.top = -index*liHeight+"px"; }function goup(){ var li = document.getElementsByTagName("li"); //获取单个li宽度(单张图片高度) var liHeight = li[0].scrollHeight; var goup=document.getElementsByClassName("goup"); var lancer=document.getElementsByClassName("lancer")[0]; if(index>0){ index--; }else{ index=4; } lancer.style.top = -index*liHeight+"px";}
HTML代码
li { list-style: none; } .archer { position: absolute; top: 0%; display: none; } .active { display: block; } button { position: absolute; top: 70%; width: 50px; } #goup { left: 400px; } #godown { left: 0px; }
var pic = document.getElementsByTagName("li"); var archer = document.getElementsByClassName("archer"); var goup = document.getElementById("goup"); var godown = document.getElementById("godown"); var index = 0; goup.onclick = function() { for (var i = 0; i < pic.length; i++) { pic[i].className = "archer"; } if (index < 4) { index++; } else { index = 0; } pic[index].className = "active"; } godown.onclick = function() { for (var i = 0; i < pic.length; i++) { pic[i].className = "archer"; } if (index > 0) { index--; } else { index = 4; } pic[index].className = "active"; }
您可能感兴趣的文章:
上一条:
js滚轮事件 自定义滚动条的实现
下一条:
js键盘事件实现人物的行走
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号