自己搞个网站,wordpress更新慢,网站升级改造建设方案,深圳网页设计公司在哪效果图
先来看下效果图#xff0c;嫌麻烦就不用具体图片来实现了#xff0c;主要是理清思路。#xff08;自动轮播#xff0c;左右按钮切换图片#xff0c;小圆点切换图片#xff0c;鼠标移入暂停轮播#xff0c;鼠标移出继续轮播#xff09; HTML
首先是html内容嫌麻烦就不用具体图片来实现了主要是理清思路。自动轮播左右按钮切换图片小圆点切换图片鼠标移入暂停轮播鼠标移出继续轮播 HTML
首先是html内容布局很简单一个图片列表一个点列表两个按钮。注意data-index使用HTML5中的data-xx属性来嵌入自定义数据下面JS代码会提到。记得给默认显示的图片和对应的小圆点加上active类哦。
div classwrapul classlistli classitem active0/lili classitem1/lili classitem2/lili classitem3/lili classitem4/li/ulul classpointListli classpoint active data-index 0/lili classpoint data-index 1/lili classpoint data-index 2/lili classpoint data-index 3/lili classpoint data-index 4/li/ulbutton classbtn idleftBtn /button button classbtn idrightBtn /button
/div CSS
思路父容器list相对定位item绝对定位实现让所有图片重叠在父容器内。利用z-index来设置图片高度图片高度最高会显示在顶层上。那么整个容器中左右切换按钮和小圆点始终要在最顶层不能被图片覆盖所以他们的z-index一定要比图片高。active是一个样式给某张图片绑定这个样式就能在最上层显示。然后就是图片切换的渐变效果opacity完全不透明到透明再加个transition动画效果。最后就是cursor给小圆点添加“小手指”其他就没什么好说的了。
style.wrap {width: 800px;height: 400px;position: relative;}
.list {width: 800px;height: 400px;position: relative;padding-left: 0px;}
.item {width: 100%;height: 100%;list-style: none;position: absolute;left: 0;opacity: 0;transition: all .8s;}
.item:nth-child(1) {background-color: skyblue;}
.item:nth-child(2) {background-color: yellowgreen;}
.item:nth-child(3) {background-color: rebeccapurple;}
.item:nth-child(4) {background-color: pink;}
.item:nth-child(5) {background-color: orange;}
.item.active {z-index: 10;opacity: 1;}
.btn {width: 60px;height: 100px;z-index: 100;top: 150px;position: absolute;}
#leftBtn {left: 0px;}
#rightBtn {right: 0px;}
.pointList {list-style: none;padding-left: 0px;position: absolute;right: 20px;bottom: 20px;z-index: 200;}
.point {width: 10px;height: 10px;background-color: antiquewhite;border-radius: 100%;float: left;margin-right: 8px;border-style: solid;border-width: 2px;border-color: slategray;cursor: pointer; }
.point.active{background-color: cadetblue;}/style Javascript
Index可以说是整个代码里面的核心先封装一个清除active的方法这里面要清除图片的active显示在最上层比如切换到下一张图上张图的active就要清除。还有point的active图片对应小圆点改变样式。然后goIndex这个方法就是给图片和对应的小圆点同时加上active左右按钮绑定的方法就不说了。
用getAttribute拿到刚才给li标签绑定的data-index属性绑定图片index pointindex就能实现点击小圆点图片切换了。由于上面goIndex方法早已经绑定好了给图片添加active样式的时候也给小圆点添加的样式了就可以实现图片切换小圆点跟随变化的效果。
scriptvar items document.querySelectorAll(.item);//图片节点var points document.querySelectorAll(.point)//点var left document.getElementById(leftBtn);var right document.getElementById(rightBtn);var all document.querySelector(.wrap)var index 0;var time 0;//定时器跳转参数初始化//封装一个清除active方法var clearActive function () {for (i 0; i items.length; i) {items[i].className item;}for (j 0; j points.length; j) {points[j].className point;}}
//改变active方法var goIndex function () {clearActive();items[index].className item active;points[index].className point active}//左按钮事件var goLeft function () {if (index 0) {index 4;} else {index--;}goIndex();}
//右按钮事件var goRight function () {if (index 4) {index;} else {index 0;}goIndex();}//绑定点击事件监听left.addEventListener(click, function () {goLeft();time 0;//计时器跳转清零})
right.addEventListener(click, function () {goRight();time 0;//计时器跳转清零})
for(i 0;i points.length;i){points[i].addEventListener(click,function(){var pointIndex this.getAttribute(data-index)index pointIndex;goIndex();time 0;//计时器跳转清零})}//计时器轮播效果var timer;function play(){timer setInterval(() {time ;if(time 20 ){goRight();time 0;} },100)}play();//移入清除计时器all.onmousemove function(){clearInterval(timer)}//移出启动计时器all.onmouseleave function(){play();}/script
总结这个简单的轮播图实现例子是第一次写最容易理解逻辑最清晰的一种。下面我把完整的代码块放出来直接复制粘贴就可以运行。
!DOCTYPE html
html
headstyle.wrap {width: 800px;height: 400px;position: relative;}
.list {width: 800px;height: 400px;position: relative;padding-left: 0px;}
.item {width: 100%;height: 100%;list-style: none;position: absolute;left: 0;opacity: 0;transition: all .8s;}
.item:nth-child(1) {background-color: skyblue;}
.item:nth-child(2) {background-color: yellowgreen;}
.item:nth-child(3) {background-color: rebeccapurple;}
.item:nth-child(4) {background-color: pink;}
.item:nth-child(5) {background-color: orange;}
.item.active {z-index: 10;opacity: 1;}
.btn {width: 60px;height: 100px;z-index: 100;top: 150px;position: absolute;}
#leftBtn {left: 0px;}
#rightBtn {right: 0px;}
.pointList {list-style: none;padding-left: 0px;position: absolute;right: 20px;bottom: 20px;z-index: 200;}
.point {width: 10px;height: 10px;background-color: antiquewhite;border-radius: 100%;float: left;margin-right: 8px;border-style: solid;border-width: 2px;border-color: slategray;cursor: pointer; }
.point.active{background-color: cadetblue;}/style
/head
bodydiv classwrapul classlistli classitem active0/lili classitem1/lili classitem2/lili classitem3/lili classitem4/li/ulul classpointListli classpoint active data-index 0/lili classpoint data-index 1/lili classpoint data-index 2/lili classpoint data-index 3/lili classpoint data-index 4/li/ulbutton classbtn idleftBtn /button button classbtn idrightBtn /button
/divscriptvar items document.querySelectorAll(.item);//图片var points document.querySelectorAll(.point)//点var left document.getElementById(leftBtn);var right document.getElementById(rightBtn);var all document.querySelector(.wrap)var index 0;var time 0;//定时器跳转参数初始化//清除active方法var clearActive function () {for (i 0; i items.length; i) {items[i].className item;}for (j 0; j points.length; j) {points[j].className point;}}
//改变active方法var goIndex function () {clearActive();items[index].className item active;points[index].className point active}//左按钮事件var goLeft function () {if (index 0) {index 4;} else {index--;}goIndex();}
//右按钮事件var goRight function () {if (index 4) {index;} else {index 0;}goIndex();}//绑定点击事件监听left.addEventListener(click, function () {goLeft();time 0;//计时器跳转清零})
right.addEventListener(click, function () {goRight();time 0;//计时器跳转清零})
for(i 0;i points.length;i){points[i].addEventListener(click,function(){var pointIndex this.getAttribute(data-index)index pointIndex;goIndex();time 0;//计时器跳转清零})}//计时器var timer;function play(){timer setInterval(() {time ;if(time 20 ){goRight();time 0;} },100)}play();//移入清除计时器all.onmousemove function(){clearInterval(timer)}//移出启动计时器all.onmouseleave function(){play();}/script
/body
/html 文章转载自: http://www.morning.fgwzl.cn.gov.cn.fgwzl.cn http://www.morning.lgwpm.cn.gov.cn.lgwpm.cn http://www.morning.thntp.cn.gov.cn.thntp.cn http://www.morning.zntf.cn.gov.cn.zntf.cn http://www.morning.zmpqh.cn.gov.cn.zmpqh.cn http://www.morning.nhdmh.cn.gov.cn.nhdmh.cn http://www.morning.nndbz.cn.gov.cn.nndbz.cn http://www.morning.prsxj.cn.gov.cn.prsxj.cn http://www.morning.lqytk.cn.gov.cn.lqytk.cn http://www.morning.lwnb.cn.gov.cn.lwnb.cn http://www.morning.c7498.cn.gov.cn.c7498.cn http://www.morning.twpq.cn.gov.cn.twpq.cn http://www.morning.kbqqn.cn.gov.cn.kbqqn.cn http://www.morning.xqgh.cn.gov.cn.xqgh.cn http://www.morning.rnqrl.cn.gov.cn.rnqrl.cn http://www.morning.fgwzl.cn.gov.cn.fgwzl.cn http://www.morning.zcqbx.cn.gov.cn.zcqbx.cn http://www.morning.srwny.cn.gov.cn.srwny.cn http://www.morning.lqgfm.cn.gov.cn.lqgfm.cn http://www.morning.cgdyx.cn.gov.cn.cgdyx.cn http://www.morning.jzsgn.cn.gov.cn.jzsgn.cn http://www.morning.zcwzl.cn.gov.cn.zcwzl.cn http://www.morning.jjwt.cn.gov.cn.jjwt.cn http://www.morning.tqfnf.cn.gov.cn.tqfnf.cn http://www.morning.bkqdg.cn.gov.cn.bkqdg.cn http://www.morning.bpmnc.cn.gov.cn.bpmnc.cn http://www.morning.pqppj.cn.gov.cn.pqppj.cn http://www.morning.qtbnm.cn.gov.cn.qtbnm.cn http://www.morning.qpnmd.cn.gov.cn.qpnmd.cn http://www.morning.lwlnw.cn.gov.cn.lwlnw.cn http://www.morning.wngpq.cn.gov.cn.wngpq.cn http://www.morning.rlrxh.cn.gov.cn.rlrxh.cn http://www.morning.jfqqs.cn.gov.cn.jfqqs.cn http://www.morning.nnwmd.cn.gov.cn.nnwmd.cn http://www.morning.kjtdy.cn.gov.cn.kjtdy.cn http://www.morning.ztmkg.cn.gov.cn.ztmkg.cn http://www.morning.jcxqc.cn.gov.cn.jcxqc.cn http://www.morning.znrgq.cn.gov.cn.znrgq.cn http://www.morning.hnzrl.cn.gov.cn.hnzrl.cn http://www.morning.gkdhf.cn.gov.cn.gkdhf.cn http://www.morning.hongjp.com.gov.cn.hongjp.com http://www.morning.rddlz.cn.gov.cn.rddlz.cn http://www.morning.dkqyg.cn.gov.cn.dkqyg.cn http://www.morning.ntcmrn.cn.gov.cn.ntcmrn.cn http://www.morning.lgqdl.cn.gov.cn.lgqdl.cn http://www.morning.drwpn.cn.gov.cn.drwpn.cn http://www.morning.gtmgl.cn.gov.cn.gtmgl.cn http://www.morning.nqgjn.cn.gov.cn.nqgjn.cn http://www.morning.qytby.cn.gov.cn.qytby.cn http://www.morning.sfnr.cn.gov.cn.sfnr.cn http://www.morning.lhhkp.cn.gov.cn.lhhkp.cn http://www.morning.znqxt.cn.gov.cn.znqxt.cn http://www.morning.sbjbs.cn.gov.cn.sbjbs.cn http://www.morning.rqsr.cn.gov.cn.rqsr.cn http://www.morning.zgdnz.cn.gov.cn.zgdnz.cn http://www.morning.ttxnj.cn.gov.cn.ttxnj.cn http://www.morning.lkgqb.cn.gov.cn.lkgqb.cn http://www.morning.kpbgp.cn.gov.cn.kpbgp.cn http://www.morning.ejknty.cn.gov.cn.ejknty.cn http://www.morning.xxiobql.cn.gov.cn.xxiobql.cn http://www.morning.gjmll.cn.gov.cn.gjmll.cn http://www.morning.sglcg.cn.gov.cn.sglcg.cn http://www.morning.ckhyj.cn.gov.cn.ckhyj.cn http://www.morning.wcft.cn.gov.cn.wcft.cn http://www.morning.ryfpx.cn.gov.cn.ryfpx.cn http://www.morning.jydhl.cn.gov.cn.jydhl.cn http://www.morning.cwyfs.cn.gov.cn.cwyfs.cn http://www.morning.nzzws.cn.gov.cn.nzzws.cn http://www.morning.mtxrq.cn.gov.cn.mtxrq.cn http://www.morning.mqtzd.cn.gov.cn.mqtzd.cn http://www.morning.wfykn.cn.gov.cn.wfykn.cn http://www.morning.mjqms.cn.gov.cn.mjqms.cn http://www.morning.ywqw.cn.gov.cn.ywqw.cn http://www.morning.mrgby.cn.gov.cn.mrgby.cn http://www.morning.ylzdx.cn.gov.cn.ylzdx.cn http://www.morning.mprky.cn.gov.cn.mprky.cn http://www.morning.cykqg.cn.gov.cn.cykqg.cn http://www.morning.kyzja.com.gov.cn.kyzja.com http://www.morning.rlhgx.cn.gov.cn.rlhgx.cn http://www.morning.wxlzr.cn.gov.cn.wxlzr.cn