移動端輪播外掛程式

來源:互聯網
上載者:User

標籤:

<div class="slider">    <div class="pic" id="pic">        <div id="bg1" class="bg fadein"></div>        <div id="bg2" class="bg"></div>        <div id="bg3" class="bg"></div>        <div id="bg4" class="bg"></div>        <div id="bg5" class="bg"></div>    </div>    <ul class="btn" id="btn">        <li class="active"></li>        <li>2</li>        <li>3</li>        <li>4</li>        <li>5</li>    </ul></div>css.slider{position:relative;width:100%;height:100%}.bg{position:absolute;left:0;top:0;width:100vw;height:100vh;opacity:0;filter:alpha(opacity=0);-webkit-transition:opacity 1s linear;-moz-transition:opacity 1s linear;-ms-transition:opacity 1s linear;-o-transition:opacity 1s linear;transition:opacity 1s linear}#bg1{background:url(https://ss1.baidu.com/9vo3dSag_xI4khGko9WTAnF6hhy/super/whfpf%3D425%2C260%2C50/sign=5b8ce96a0af431adbc8710792d0b989d/63d9f2d3572c11df40d7b3db652762d0f603c2c0.jpg) no-repeat;background-size:cover}#bg2{background:url(https://ss2.baidu.com/-vo3dSag_xI4khGko9WTAnF6hhy/super/whfpf%3D425%2C260%2C50/sign=bbc9424198510fb3784c24d7bf0efca7/9825bc315c6034a803dbb479cd13495409237608.jpg) no-repeat;background-size:cover}#bg3{background:url(https://ss0.baidu.com/7Po3dSag_xI4khGko9WTAnF6hhy/super/whfpf%3D425%2C260%2C50/sign=2725a1ea740e0cf3a0a21dbb6c7bc62d/faedab64034f78f04041960b7f310a55b2191cfb.jpg) no-repeat;background-size:cover}#bg4{background:url(https://ss1.baidu.com/9vo3dSag_xI4khGko9WTAnF6hhy/super/whfpf%3D425%2C260%2C50/sign=5b8ce96a0af431adbc8710792d0b989d/63d9f2d3572c11df40d7b3db652762d0f603c2c0.jpg) no-repeat;background-size:cover}#bg5{background:url(https://ss2.baidu.com/-vo3dSag_xI4khGko9WTAnF6hhy/super/whfpf%3D425%2C260%2C50/sign=bbc9424198510fb3784c24d7bf0efca7/9825bc315c6034a803dbb479cd13495409237608.jpg) no-repeat;background-size:cover}*{margin:0;padding:0}.btn{position:fixed;bottom:50px;width:100%;height:30px;text-align:center}.btn li{float:left;width:20%;height:5px;text-indent:-999px;background:grey}.fadein{opacity:1;filter:alpha(opacity=100)}.btn li.active{background:red}li{list-style-type:none}.pic{width:100vw;height:100vh}.box{width:400px;height:400px;background:red}body{height:3000px}jsvar pic=document.getElementById(‘pic‘);var touchx= 0,    alreadymove=true,    currentimg= 0,    imglen=document.getElementsByClassName(‘bg‘).length;pic.addEventListener(‘touchstart‘, function (e) {    e.preventDefault();    if(alreadymove){        var touched= e.touches[0];        touchx= touched.pageX;        alreadymove=false;    }},false);pic.addEventListener(‘touchmove‘, function (e) {    if(!alreadymove){        var touched= e.changedTouches[0];        var offsetX=touched.pageX;        if(offsetX+20 <touchx){            if( currentimg >= imglen-1){                currentimg=0;            }else{                currentimg++;            }            showpic(currentimg);            alreadymove=true;        }        if(offsetX-20 >touchx){            if(currentimg<=0){                currentimg=imglen-1;            }else{                currentimg--;            }            showpic(currentimg);            alreadymove=true;        }    }},false);pic.addEventListener(‘touchend‘, function (e) {    e.preventDefault();},false);function showpic(index){    /*hide all pic first*/    hideall();    /*show the index pic*/    var allpic=document.getElementsByClassName(‘bg‘);    allpic[index].classList.add(‘fadein‘);    /*show the index btn*/    showbtn(index);}function hideall(){    var allpic=document.getElementsByClassName(‘bg‘);    Array.prototype.forEach.call(allpic, function (element,index,array) {        element.classList.remove(‘fadein‘);    });}function showbtn(index){    var btns=document.getElementById(‘btn‘).getElementsByTagName(‘li‘);    Array.prototype.forEach.call(btns, function (element,index,array) {       element.classList.remove(‘active‘);    });    btns[index].classList.add(‘active‘);}

 

移動端輪播外掛程式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.