欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來(lái)到入門(mén)教程網(wǎng)!

JavaScript

當(dāng)前位置:主頁(yè) > 網(wǎng)絡(luò)編程 > JavaScript >

JS實(shí)現(xiàn)普通輪播圖特效

來(lái)源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:JavaScript|點(diǎn)擊: 次

本文實(shí)例為大家分享了JS實(shí)現(xiàn)輪播圖特效的具體代碼,供大家參考,具體內(nèi)容如下

知識(shí)點(diǎn)

輪播圖思想:

① 建立一個(gè)全局變量索引,始終標(biāo)記當(dāng)前顯示圖片。
② 根據(jù)當(dāng)前圖片的數(shù)量,動(dòng)態(tài)創(chuàng)建下方的●圖片指示器。
③ 輪播圖的初始狀態(tài)為第一張圖片在中間,剩余所有圖片均放在即將顯示圖片位置。
④ 當(dāng)點(diǎn)擊>的時(shí)候,當(dāng)前圖片調(diào)用動(dòng)畫(huà)移動(dòng)函數(shù)進(jìn)行左移,與此同時(shí)新的一張圖片調(diào)用動(dòng)畫(huà)函數(shù)移入到div中,而會(huì)將下一張展示的圖片移動(dòng)到div右側(cè)。
⑤ 需要進(jìn)行邊界判斷,如果當(dāng)前的圖片大于圖片數(shù)量或者小于等于0,重新給索引賦值。
⑥ 當(dāng)點(diǎn)擊圖片指示器的時(shí)候,首先判定點(diǎn)擊的與索引的位置關(guān)系,然后進(jìn)行動(dòng)畫(huà)移動(dòng)。
⑦ 給div添加定時(shí)器,自動(dòng)移動(dòng)圖片。當(dāng)鼠標(biāo)進(jìn)入div,刪除定時(shí)器,當(dāng)鼠標(biāo)移出div,設(shè)置定時(shí)器。

運(yùn)行效果

1.自動(dòng)輪播
2.點(diǎn)擊左右切換圖片
3.點(diǎn)擊下方圖片指示器切換圖片

代碼

引入MyTools.js庫(kù)

1.html

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>Title</title>
 <link rel="stylesheet" href="1.css" rel="external nofollow" >
</head>
<body>
<div id="box">
 <div id="box_content">
 <div class="box_img"><img src="casual01.jpg" alt=""></div>
 <div class="box_img"><img src="casual02.jpg" alt=""></div>
 <div class="box_img"><img src="casual03.jpg" alt=""></div>
 <div class="box_img"><img src="casual04.jpg" alt=""></div>
 <div class="box_img"><img src="casual05.jpg" alt=""></div>
 </div>
 <div id="box_control">
 <a href="javascript:;" class="box_control_left"><i><</i></a>
 <a href="javascript:;" class="box_control_right"><i>></i></a>
 <ul>
 </ul>
 </div>
</div>
<script src="../JavaScript學(xué)習(xí)/00MyTools/MyTools.js"></script>
<script src="1.js"></script>
</body>
</html>

2.css

*{margin: 0;padding: 0;}
a{
 color: #999;
 text-decoration: none;
 position: absolute;
 top: 50%;
 transform: translateY(-50%);
 background-color: rgba(0, 0, 0, .4);
}
a:hover{
 color: #f8b62b;
}
i{
 font-size: 50px;
 font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
#box{
 height: 482px;
 width: 830px;
 background-color: red;
 position: absolute;
 left: 50%;
 top: 50%;
 transform: translate(-50%,-50%);
 overflow: hidden;
}
#box_content{
 height: 100%;
 width: 100%;
 cursor: pointer;
}
#box_content img{
 position: absolute;
 vertical-align: top;
 height: 100%;
 width: 100%;
 /*left: 830px;*/
}
.box_img{
 width: 100%;
 height: 100%;
 position: absolute;}
.box_control_right{
 position: absolute;
 right: 0;
}
.box_control_left{
 position: absolute;
 left: 0;
}
ul{
 position: absolute;
 bottom: 30px;
 left: 50%;
 transform: translateX(-50%);
 display: flex;
 justify-content:space-evenly;
}
ul>li{
 list-style: none;
 width: 16px;
 height: 16px;
 background-color: #fff;
 margin: 0 3px;
 border-radius: 50%;
 cursor: pointer;
}
ul>li.current{
 background-color: darkorange;
}

3.js

window.addEventListener('load',function (ev) {
 // 輪播圖
 (function () {
 // 1. 獲取需要標(biāo)簽
 var boxContent = myTool.$('box_content');
 var contentImg = boxContent.children;
 var boxControl = myTool.$('box_control');
 var controlBottom = boxControl.children[2];
 // 2. 全局索引
 var iNow = 0;
 // 3. 根據(jù)圖片個(gè)數(shù)動(dòng)態(tài)添加下方圖片指示器
 for (var i = 0; i < contentImg.length; i++) {
 var li = document.createElement('li');
 controlBottom.insertBefore(li,controlBottom.children[0]);
 }
 // 4. 讓第一個(gè)圖片指示器選中
 controlBottom.children[0].className = 'current';
 // 5. 讓除了第一張圖片以外所有圖片進(jìn)入待顯示區(qū)域
 var scrollImgWidth = boxContent.offsetWidth;
 for (var j = 1; j < contentImg.length; j++) {
 contentImg[j].style.left = scrollImgWidth + 'px';
 }
 // 6. 處理左右兩側(cè)點(diǎn)擊
 var cPrev = boxControl.children[0];
 var cNext = boxControl.children[1];
 // 6.1 點(diǎn)擊左邊
 cPrev.addEventListener('click',function (evt) {
 // 1. 當(dāng)前可視區(qū)域圖片快速右移
 // 2. 上一張幻燈片出現(xiàn)在可視區(qū)域左側(cè)
 // 3. 讓這張幻燈片做動(dòng)畫(huà)進(jìn)入
 myTool.slowMoving(contentImg[iNow],{'left':scrollImgWidth},null);
 iNow--;
 // 邊界處理
 if (iNow < 0){
 iNow = contentImg.length - 1;
 }
 contentImg[iNow].style.left = -scrollImgWidth + 'px';
 myTool.slowMoving(contentImg[iNow],{'left':0},null);
 // 切換索引
 changeIndex();

 },false);
 // 6.2 點(diǎn)擊右邊
 cNext.addEventListener('click',function (evt) {
 autoPlay();
 },false);
 // 7. 下側(cè)圖片指示器操作
 for (var k = 0; k < controlBottom.children.length; k++) {
 // 取出單個(gè)li標(biāo)簽
 var bottomLi = controlBottom.children[k];
 // 監(jiān)聽(tīng)鼠標(biāo)進(jìn)入
 (function (index) {
 bottomLi.addEventListener('mouseover',function (evt) {
  // 比較當(dāng)前索引和點(diǎn)擊指示器位置關(guān)系
  if (index > iNow){
  myTool.slowMoving(contentImg[iNow],{'left':-scrollImgWidth},null);
  contentImg[index].style.left = scrollImgWidth + 'px';
  }else if(index < iNow){
  myTool.slowMoving(contentImg[iNow],{'left':scrollImgWidth},null);
  contentImg[index].style.left = -scrollImgWidth + 'px';
  }
  iNow = index;
  myTool.slowMoving(contentImg[iNow],{'left':0});
  // 切換索引
  changeIndex();
 },false);
 })(k)
 }

 /**
 * 切換索引操作
 */
 function changeIndex() {
 for (var i = 0; i < controlBottom.children.length; i++) {
 controlBottom.children[i].className = '';
 }
 // 當(dāng)前的被選中
 controlBottom.children[iNow].className = 'current';
 }

 /**
 * 點(diǎn)擊右側(cè)和圖片自動(dòng)運(yùn)動(dòng)操作
 */
 function autoPlay(){
 // 1. 當(dāng)前可視區(qū)域圖片快速左移
 // 2. 下一張圖片出現(xiàn)在可視區(qū)域右側(cè)
 // 3. 讓這張圖片做動(dòng)畫(huà)進(jìn)入
 myTool.slowMoving(contentImg[iNow],{'left':-scrollImgWidth},null);
 iNow++;
 // 邊界處理
 if (iNow >= contentImg.length) {
 iNow = 0;
 }
 contentImg[iNow].style.left = scrollImgWidth + 'px';
 myTool.slowMoving(contentImg[iNow], {"left": 0},null);
 // 切換索引
 changeIndex();
 }

 // 8. 設(shè)置定時(shí)器
 var timerId = setInterval(autoPlay,2000);
 // 9. 鼠標(biāo)進(jìn)入圖片div后設(shè)置和清除定時(shí)器
 myTool.$('box').addEventListener('mouseover',function () {
 clearInterval(timerId);
 });
 myTool.$('box').addEventListener('mouseout',function () {
 timerId = setInterval(autoPlay,2000);
 });

 })();
},false);

更多關(guān)于輪播圖效果的專題,請(qǐng)點(diǎn)擊下方鏈接查看學(xué)習(xí)

javascript圖片輪播效果匯總

jquery圖片輪播效果匯總

Bootstrap輪播特效匯總

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。

上一篇:uni-app 支持多端第三方地圖定位的方法

欄    目:JavaScript

下一篇:nodejs開(kāi)發(fā)一個(gè)最簡(jiǎn)單的web服務(wù)器實(shí)例講解

本文標(biāo)題:JS實(shí)現(xiàn)普通輪播圖特效

本文地址:http://mengdiqiu.com.cn/a1/JavaScript/9331.html

網(wǎng)頁(yè)制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語(yǔ)言數(shù)據(jù)庫(kù)服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有