JS实现小图放大轮播页面效果入下(图片为优行商旅页面照片):
实现效果:图片自动轮播,鼠标移入停止,移出继续轮播点击下方小图可以实现切换
步骤一:建立HTML布局,具体如下:
其中div为图片轮播区域,li用于放置小图
步骤二:CSS布局
*{ margin:0; padding:0; } ul{ list-style: none; height:auto; position: absolute; top:95%; left:32%; } #carousel{ width:100%; height:400px; background-image: url(images/1.jpg); background-repeat: no-repeat; background-position: center; position: relative; } li{ float:left; margin-right: 20px; } span{ display: block; width:110px; height:41px; background-size: 110px 41px; border:none; } li:nth-child(1) span{ background-image: url(images/1.jpg); border:2px solid orange; } li:nth-child(2) span{ background-image: url(images/2.jpg); } li:nth-child(3) span{ background-image: url(images/3.jpg); } li:nth-child(4) span{ background-image: url(images/4.jpg); }
通过定位使小图显示在下方,此时轮播区域显示的为第一张图片
步骤三:添加JS逻辑(其中该代码注释中的圆点是指轮播图下方小图)
let cnt=1;//计数器let ulctrl=document.getElementById("ulctrl");//圆点控制器let lis=ulctrl.children;//圆点们let linow=lis[0];//初始化当前圆点为第一个let clock;//声明计时器var carousel=document.getElementById("carousel");//背景容器for(let i=0;i