轮播图的几种实现方式

您所在的位置:网站首页 js实现简单轮播图的方式是什么 轮播图的几种实现方式

轮播图的几种实现方式

2024-07-16 12:48| 来源: 网络整理| 查看: 265

一、z-index透明度轮播

原理:将所有img元素重叠在一起,为想要展示的图片的z-index属性,设置为最大值。

Document * { margin: 0; padding: 0; } div { position: relative; width: 500px; height: 300px; z-index: 10000; } div img { position: absolute; z-index: 10; opacity: 0; transition: all 0.5s ease; } div button { width: 50px; position: absolute; z-index: 1000; top: 150px; cursor: pointer } #btnLeft { left: 0; } #btnRignt { right: 0; } .active { z-index: 1000; opacity: 1; } ul { position: absolute; padding: 0; list-style: none; z-index: 1000; right: 20px; bottom: 20px; cursor: pointer; } li { float: left; width: 8px; height: 8px; background-color: rgba(0, 0, 0, 0.4); border-radius: 100%; margin-right: 10px; border: 2px solid black; } .liwhite { background-color: white } > var btnLeft = document.getElementById('btnLeft') var btnRignt = document.getElementById('btnRignt') var item = document.getElementsByClassName('item') var li = document.getElementsByTagName('li') var div = document.getElementById('div') var index = 0 //移除所有的active项 function removeClassActive() { for (var i = 0; i = 4) { index = -1 } else if (index *{ margin: 0; padding: 0; } div.content{ position: relative; overflow: hidden; width: 700px; height: 400px; border:1px solid beige; background-color: aqua; } ul{ position: absolute; list-style: none; } ul.top>li{ float: left; width: 700px; height: 400px; } img{ width: 100%; height: 100%; } button.perv{ position: absolute; top: 191px; left:0; } button.next{ position: absolute; top: 191px; right:0; } ul.bottom{ position: absolute; top: 336px; left: 20px; } ul.bottom>li{ float: left; width: 25px; height: 25px; margin-left:15px; border: 1px solid #00FFFF; text-align: center; line-height: 25px; cursor: pointer; } .red{ background-color: red; } function $(n){ return document.querySelector(n); } window.onload=function(){ var liIndex=1; var liWidth,liLenth,lilen,timer,timer2; go(); function go(){ //复制前后li var copy_li1=$(".top>li:first-of-type").cloneNode(true); $(".top").appendChild(copy_li1); var copy_lilast=$(".top>li:nth-of-type(5)").cloneNode(true); $(".top").insertBefore(copy_lilast,$(".top>li:first-of-type")); //给ul宽度 liWidth=$(".top>li").clientWidth; lilen=document.querySelectorAll(".top>li").length; $(".top").style.width=lilen*liWidth+"px"; $(".top").style.left=-liWidth+"px"; //左右点击 $(".perv").onclick=function(){ prev(liIndex); } $(".next").onclick=function(){ next(liIndex); } //点击子弹 var bullets=document.querySelectorAll(".bottom>li"); for(var i=0;i0?Math.ceil(speed):Math.floor(speed); $(".top").style.left=new_left+speed+"px"; },10); console.log(liIndex); } } perv next 1 2 3 4 5


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3