九色国产,午夜在线视频,新黄色网址,九九色综合,天天做夜夜做久久做狠狠,天天躁夜夜躁狠狠躁2021a,久久不卡一区二区三区

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
純js輪播

純js實現(xiàn):

要求:算了,還是先看圖吧


01.gif

實現(xiàn)效果:
圖片自動輪播,鼠標移入停止,移出繼續(xù)輪播
點擊左右按鈕實現(xiàn)切換
點擊下標焦點實現(xiàn)切換

1、首先實現(xiàn)無縫滾動:
效果:


02.gif

原理:
讓ul里的第一個 li 和最后一個 li 內(nèi)容相同;
通過改變left值,讓ul在box中移動;
當移動到最后一個的時候,在讓ul回到其實位置;


屏幕快照 2016-11-30 下午4.49.26.png

代碼實現(xiàn):

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>無縫滾動</title></head><style type="text/css">    *{        margin: 0;        padding: 0;    }    .box{        background: red;        width: 600px;        height: 300px;        overflow: hidden;        margin:100px auto;        position: relative;    }    img{        width: 600px;        height: 300px;        vertical-align: top;/*取消底邊的3px */    }    ul{         width: 500%;        height: 300px;        list-style: none;        position: absolute;        left: 0;        top: 0;    }    li{        float: left;    }</style><body>    <div class="box" id="box">        <ul id="inner-box">            <li><img src="banner/banner1.jpg"></li>            <li><img src="banner/banner2.jpg"></li>            <li><img src="banner/banner3.jpg"></li>            <li><img src="banner/banner4.jpg"></li>            <li><img src="banner/banner1.jpg"></li>        </ul>     <ol class="">        <li class="current">1</li>        <li>2</li>        <li>3</li>        <li>4</li>        <li>5</li>    </ol>    </div></body><script type="text/javascript">     var oBox = document.getElementById("box");     var oUl = document.getElementById("inner-box");     var a = 0;          //定義一個變量用于設置left值     var timer = null;   //定義一個計時器     var target = 500;     timer = setInterval(autoPlay,10);// 定義計時器每25毫秒執(zhí)行一次     function autoPlay() { //執(zhí)行每次執(zhí)行函數(shù),left值減1         a--;         a <= -400 ? a = 0 :a;         oUl.style.left = a+"%";      }     oBox.onmouseover = function () { //移出時清除計時器          clearInterval(timer);     }     oBox.onmouseout=function(){ //移入時開始計時器           timer = setInterval(autoPlay,10);     }</script></html>

2、加入緩沖的勻速運動:
原里:改變每次變化的速度


05.gif

代碼實現(xiàn)

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>緩沖無縫滾動</title></head><style type="text/css">* {    margin: 0;    padding: 0;}.box {    background: red;    width: 600px;    height: 300px;    overflow: hidden;    margin: 100px auto;    position: relative;}img {    width: 600px;    height: 300px;    vertical-align: top;    /*取消底邊的3px */}ul {    width: 500%;    height: 300px;    list-style: none;    position: absolute;    left: 0;    top: 0;}li {    float: left;}</style><body>    <div class="box" id="box">        <ul id="inner-box">            <li><img src="banner/banner1.jpg"></li>            <li><img src="banner/banner2.jpg"></li>            <li><img src="banner/banner3.jpg"></li>            <li><img src="banner/banner4.jpg"></li>            <li><img src="banner/banner1.jpg"></li>        </ul>    </div></body><script type="text/javascript">var oBox = document.getElementById("box");var oUl = document.getElementById("inner-box");var cur = 0; //定義一個變量用于設置left值var timer = null; //定義一個計時器var target = 0;timer = setInterval(autoPlay, 2000); // 定義計時器每25毫秒執(zhí)行一次function autoPlay() { //執(zhí)行每次執(zhí)行函數(shù),left值減1    if (target <= -400) {        cur = 0;        target = -100;    } else {        target -= 100;    }    var timer1 = null;    timer1 = setInterval(autoPlay, 30); //設置定時器每30毫秒執(zhí)行一次    function autoPlay() {         if (cur == target) {            clearInterval(timer1) //大于目標值時,清空計時器        } else {            speed = (target - cur) / 7; //計算速度            speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed); //取整            cur = cur + speed;             oUl.style.left = cur + "%";        }    }}oBox.onmouseover = function() { //移出時清除計時器    clearInterval(timer);}oBox.onmouseout = function() { //移入時開始計時器    timer = setInterval(autoPlay, 2000);}</script></html>

3、添加左右點擊按鈕
效果:


03.gif


難點:


屏幕快照 2016-12-01 上午10.06.19.png
<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>緩沖無縫滾動</title></head><style type="text/css">* {    margin: 0;    padding: 0;}.box {    background: red;    width: 600px;    height: 300px;    overflow: hidden;    margin: 100px auto;    position: relative;}img {    width: 600px;    height: 300px;    vertical-align: top;    /*取消底邊的3px */}ul {    width: 500%;    height: 300px;    list-style: none;    position: absolute;    left: 0;    top: 0;}li {    float: left;}.btn span{     width: 30px;    height: 50px;    background: #4a4a4a;    display: inline-block;    position: absolute;    text-align: center;    line-height: 50px;    font-size: 24px;    opacity: 0.4;    cursor: pointer;}.btn span:hover{    opacity: 1;    color: #fff;}.btn .left{    left: 0;    top: 125px;}.btn .right{    right: 0;    top: 125px;}</style><body>    <div class="box" id="box">        <ul id="inner-box">            <li><img src="banner/banner1.jpg"></li>            <li><img src="banner/banner2.jpg"></li>            <li><img src="banner/banner3.jpg"></li>            <li><img src="banner/banner4.jpg"></li>            <li><img src="banner/banner1.jpg"></li>        </ul>        <div class="btn">            <span class="left" id="left"><</span>            <span class="right" id="right">></span>        </div>    </div></body><script type="text/javascript">var oBox = document.getElementById("box");var oUl = document.getElementById("inner-box");var oLeft = document.getElementById("left");var oRight = document.getElementById("right");var cur = 0; //定義一個變量用于設置left值var timer = null; //定義一個計時器var target = 0;var timer1 = null;timer = setInterval(autoPlay, 2000); // 定義計時器每25毫秒執(zhí)行一次function autoPlay() { //執(zhí)行每次執(zhí)行函數(shù),left值減1    if (target <= -400) {        cur = 0;        target = -100;    } else {        target -= 100;    }    sport(target);}oRight.onclick = function  (argument) {    if (target <= -400) {        cur = 0;        target = -100;    } else {        target -= 100;    }     sport(target);}   oLeft.onclick = function  (argument) {    if (target > -100) {       cur -= 400;       target = -300;     } else{        target += 100;    }    sport(target);}   function sport(tar) {    clearInterval(timer1);    timer1 = setInterval(autoPlay, 30); //設置定時器每30毫秒執(zhí)行一次    function autoPlay() {         if (cur == tar) {            clearInterval(timer1) //大于目標值時,清空計時器        } else {            speed = (tar - cur) / 7; //計算速度            speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed); //取整            cur = cur + speed;             oUl.style.left = cur + "%";        }    }}oBox.onmouseover = function() { //移出時清除計時器    clearInterval(timer);}oBox.onmouseout = function() { //移入時開始計時器    timer = setInterval(autoPlay, 2000);}</script></html>

4、添加底部焦點:

效果:在最上頭;一開始的地方


01.gif

代碼實現(xiàn):

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>標準輪播圖</title></head><style type="text/css">* {    margin: 0;    padding: 0;}.box {    width: 600px;    height: 300px;    overflow: hidden;    margin: 100px auto;    position: relative;}img {    width: 600px;    height: 300px;    vertical-align: top;    /*取消底邊的3px */}ul {    width: 500%;    height: 300px;    list-style: none;    position: absolute;    left: 0;    top: 0;}ul li {    float: left;}.btn span{     width: 30px;    height: 50px;    background: #4a4a4a;    display: inline-block;    position: absolute;    text-align: center;    line-height: 50px;    font-size: 24px;    opacity: 0.4;    cursor: pointer;}.btn span:hover{    opacity: 1;    color: #fff;}.btn .left{    left: 0;    top: 125px;}.btn .right{    right: 0;    top: 125px;}ol{    position: absolute;    bottom: 20px;    left: 40%;    list-style: none;}ol li{    width: 10px;    height: 10px;    border-radius: 10px;    border: 1px solid #fff;    float: left;    margin: 0 4px;}</style><body>    <div class="box" id="box">        <ul id="inner-box">            <li><img src="banner/banner1.jpg"></li>            <li><img src="banner/banner2.jpg"></li>            <li><img src="banner/banner3.jpg"></li>            <li><img src="banner/banner4.jpg"></li>            <li><img src="banner/banner1.jpg"></li>        </ul>        <ol id="ol">            <li></li>            <li></li>            <li></li>            <li></li>        </ol>        <div class="btn">            <span class="left" id="left"><</span>            <span class="right" id="right">></span>        </div>    </div></body><script type="text/javascript">var oBox = document.getElementById("box");var oUl = document.getElementById("inner-box");var oLeft = document.getElementById("left");var oRight = document.getElementById("right");var cur = 0; //定義一個變量用于設置left值var timer = null; //定義一個計時器var target = 0;var timer1 = null;var i = 0;timer = setInterval(autoPlay, 2000); // 定義計時器每25毫秒執(zhí)行一次function autoPlay() { //執(zhí)行每次執(zhí)行函數(shù),left值減1    if (target <= -400) {        cur = 0;        target = -100;    } else {        target -= 100;    }    sport(target);    btnBottom();}oRight.onclick = function  (argument) {    if (target <= -400) {        cur = 0;        target = -100;    } else {        target -= 100;    }     sport(target);     btnBottom();}   oLeft.onclick = function  (argument) {    if (target > -100) {       cur -= 400;       target = -300;     } else{        target += 100;    }    sport(target);    btnBottom();}   // 增加下標顯示效果btnBottom(i)function  btnBottom() {    i = -(target/100);    i == 4 ? i = 0 : i;     var oOl = document.getElementById("ol");    var oLi = oOl.getElementsByTagName("li");    for( j=0 ; j<oLi.length ; j++){      oLi[j].style.background = '';    }    oLi[i].style.background = '#fff';}// 加點擊事件var oOl = document.getElementById("ol");var oLi = oOl.getElementsByTagName("li");for( j=0 ; j<oLi.length ; j++){    oLi[j].index = j    oLi[j].onclick = function() {           target = -(this.index*100);           sport(target);           btnBottom()    }}function sport(tar) {    clearInterval(timer1);    timer1 = setInterval(autoPlay, 30); //設置定時器每30毫秒執(zhí)行一次    function autoPlay() {         if (cur == tar) {            clearInterval(timer1) //大于目標值時,清空計時器        } else {            speed = (tar - cur) / 7; //計算速度            speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed); //取整            cur = cur + speed;             oUl.style.left = cur + "%";        }    }}oBox.onmouseover = function() { //移出時清除計時器    clearInterval(timer);}oBox.onmouseout = function() { //移入時開始計時器    timer = setInterval(autoPlay, 2000);}</script></html>

百度云鏈接:http://pan.baidu.com/s/1mi14ijY 密碼:d84v



作者:東陽啊
鏈接:http://www.jianshu.com/p/e0d3ca1ddb57
來源:簡書
著作權歸作者所有。商業(yè)轉(zhuǎn)載請聯(lián)系作者獲得授權,非商業(yè)轉(zhuǎn)載請注明出處。
本站僅提供存儲服務,所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
HTML連載86-添加視頻、伸縮布局
jquery圖片滾動
圖片輪播效果代碼(html)
怎樣低成本的實現(xiàn)網(wǎng)頁在移動端的適配
響應式布局案例
原生js實現(xiàn)圖片切換
更多類似文章 >>
生活服務
熱點新聞
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服