国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

使用html+js+css 實現(xiàn)頁面輪播圖效果(實例講解)

2019-11-19 15:21:06
字體:
供稿:網(wǎng)友

html 頁面

<html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <link rel="stylesheet" href="carousel.css" rel="external nofollow" > <title>輪播圖效果</title></head><body> <section id="main"> <div id="picture"></div> <!-- 添加圖中按鈕 圖片輪播在js中大致成型后再寫最好--> <div id="dot"> <span></span> <span></span> <span></span> <span></span> <span></span> </div> <!-- 添加切換按鈕 --> <div id="an">  <div class="left"><</div>  <div class="right">></div> </div> </section> <script src="jquery.js"></script> <script src="carousel.js"></script></body>

css頁面 carousel.css

#main{ width: 655px; height: 361px; position: relative;}#picture{ width:100%; height: 100%;}#picture img{  width:100%; height: 100%; display: none;}#picture img:nth-child(1){ display: inline-block;}/* 設置圓點的樣式 */#dot span{ display: inline-block; width:25px; height: 25px; border-radius: 50%; background-color: gray; margin-left: 10px; opacity: 0.6}#dot{ position: absolute; right: 40px; bottom: 30px;}/* 設置頁面剛加載的圓點初始狀態(tài) 1 第一個圓點放大1.2倍 2、顏色變成藍色 */ #dot :nth-of-type(1){ transform: scale(1.2); background-color: blue; } .left ,.right{  width: 40px; height: 40px; border-radius: 50%; font-size: 30px; color: white; position: absolute; bottom: calc((100% - 40px)/2); text-align: center; } .left{ left: 15px; } .right{ right: 15px; } .left:hover ,.right:hover{ background-color: white; color:red; }

js頁面 carousel.js

for(var i=1; i<6;i++){ $('#picture').append("<img src='./../images/"+i+".jpg' >");}//給圖片轉(zhuǎn)化設置定時函數(shù)var index=0;var timer;function changeImageDot(){ $('#picture img:nth-child('+(index+1)+')').css({ display:'block', }).siblings().css({ display:'none', }); //設置隨圖片切換,對應的圓點樣式發(fā)生變化 // index+1 是因為索引是從0開始而 nth-child(i) 中的i是從1 開始的 $('#dot span:nth-child('+(index+1)+')').css({ transform: 'scale(1.2)', 'background-color': 'blue', }).siblings().css({ transform: 'scale(1)', 'background-color':'gray', });}function produceTime(){ timer=setInterval(function(){ index++; if(index==5)  index=0; changeImageDot();  },2000);}produceTime();//鼠標懸浮在圓點上 , 圓點和圖片的變化$('#dot span').mouseenter(function(){ index=$(this).index(); changeImageDot();  clearInterval(timer);  produceTime(); });//缺點:點擊切換按鈕后,圖片切換后 ,會立即切換到下一個圖片,需要設置 清除計時器后再新建一個計時器$('.left').click(function(){ index--; if(index==-1) index=4; changeImageDot();  clearInterval(timer); produceTime();});$('.right').click(function(){ index++; if(index==5) index=0; changeImageDot(); clearInterval(timer); produceTime(); 

以上這篇使用html+js+css 實現(xiàn)頁面輪播圖效果(實例講解)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持武林網(wǎng)。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 德州市| 清远市| 丰县| 绥江县| 尖扎县| 疏附县| 阿鲁科尔沁旗| 永顺县| 刚察县| 武胜县| 酉阳| 白山市| 凤山县| 基隆市| 永靖县| 天峻县| 宜川县| 贵阳市| 宿州市| 平谷区| 甘泉县| 汉寿县| 台安县| 武宁县| 大邑县| 石河子市| 平潭县| 墨玉县| 碌曲县| 天祝| 环江| 南京市| 阿拉善左旗| 垫江县| 哈密市| 明光市| 荥经县| 毕节市| 伊春市| 昌江| 民丰县|