1. 程式人生 > >輪播匯總:移動式、消失式、左右點擊+底下小圓圈

輪播匯總:移動式、消失式、左右點擊+底下小圓圈

技術 左右 pick mouse 按鈕 seo border isp 圖片

移動式:

#ad{
                width: 100px;
                height: 100px;
                border: 1px solid red;
                overflow: hidden;
            }
            img{
                width: 100px;
                height: 100px;
                /*display: none;*/
            }
            #ap{
                width
: 300px; height: 100px; border: 1px solid red; /*transition: 2s;*/ display: flex; }
<div id="ad">
            <div id="ap">
            <img src="275x182.jpg"/>
            <img src="275x185.jpg"/>
            <img src="275x183.jpg"/>
            </div>
        </div>
setInterval("lun()",2000);
function lun(){
        var a = document.getElementById("ap");
        var ml= a.style.marginLeft;
        ll=ml.substring(0,ml.length-2);
        dl=ll-100;
        if(dl == -300){
            dl=0;
        }
        a.style.marginLeft=dl+‘px‘;
    }

效果如下:

技術分享圖片

技術分享圖片

技術分享圖片

消失式:

*{
                margin
: 0 auto; padding: 0; } #one{ width: 100px; height: 100px; border: 1px solid red; } img{ width: 100px; height: 100px; display: none; }
<div id="one">
            <img src="275x182.jpg" style="display: block;"/>
            <img src="275x185.jpg"/>
            <img src="275x183.jpg"/>
        </div>

setInterval("lun1()",2000);

    var b= 0;
    function lun1(){
      var img = document.getElementsByTagName("img");
      for (var i=0;i<img.length;i++) {
          img[i].style.display="none";
      }
      b++;
      if(b>2){
          b=0;
      }
      img[b].style.display="block";
      
    }

效果與上面類似不截圖了

左右點擊+小圓點+消失式:

#wai{
                width:300px;
                height: 300px;
            }
            img{
                width: 100%;
                height: 100%;
                display: none;
            }
            #dianbox{
                height: 15px;
                width: 70px;
                position: absolute;
                border: 1px solid red;
                left: 120px;
                top: 270px;
            }
            .dian{
                width: 10px;
                height: 10px;
                border-radius: 50%;
                margin-left: 4px;
                border: 1px solid red;
                float: left;
            }
            #lbox{
                width: 25px;
                height: 75px;
                border: 1px solid red;
                position: relative;
                top: -185px;
                left: 10px;
            }
            #rbox{
                width: 25px;
                height: 75px;
                border: 1px solid red;
                position: relative;
                top: -260px;
                right: -260px;
            }
            #l{
                width: 25px;
                height: 25px;
                border: 2px solid red;
                border-right: hidden;
                border-top: hidden;
                transform: rotate(45deg);
                margin:20px 10px;
                
            }
            #r{
                width: 25px;
                height: 25px;
                border: 2px solid red;
                border-left: hidden;
                border-bottom: hidden;
                transform: rotate(45deg);
                margin:20px -10px;
            }
<div id="wai" >
            <img src="timg.jpg"/style="display: block;">
            <img src="timg1.jpg"/>
            <img src="timg2.jpg"/>
            <img src="timg3.jpg"/>
        </div>
        <div id="dianbox" >
            <div s="0" class="dian"style="border-color: green;" onclick="yuan(this,‘0‘)" onmouseover="qing()" onmouseout="hui()">
                
            </div>
            <div s="1" class="dian" onclick="yuan(this,‘1‘)" onmouseover="qing()" onmouseout="hui()">
                
            </div>
            <div s="2" class="dian" onclick="yuan(this,‘2‘)" onmouseover="qing()" onmouseout="hui()">
                
            </div>
            <div s="3" class="dian" onclick="yuan(this,‘3‘)" onmouseover="qing()" onmouseout="hui()">
                
            </div>
        </div>
        <div id="lbox">
            <div id="l">
                
            </div>
        </div>
        <div id="rbox">
            <div id="r">
                
            </div>
        </div>
var bs = 0;
    var timer = setInterval("lun()",2000);
    function lun(){    
//        圖片輪播
        bs++;
        var img = document.getElementsByTagName("img");
        if(bs>= img.length){
            bs=0;
        }
        
        
        
        for (i = 0;i<img.length;i++) {
            img[i].style.display="none";
        }
        img[bs].style.display="block";
//        圓點變色
        var dian = document.getElementsByClassName("dian");
        for (j = 0;j < img.length;j++) {
            dian[j].style.borderColor="red";
        }
        dian[bs].style.borderColor="green";
    }
    //點圓換圖清除定時器
    function yuan(x,y){
        bs=y;
        var img = document.getElementsByTagName("img");
        for(i = 0;i<img.length;i++){
            img[i].style.display="none";
        }
        img[y].style.display="block";
        var dian = document.getElementsByClassName("dian");
        for (j = 0;j<dian.length;j++) {
            dian[j].style.borderColor="red";
        }
        x.style.borderColor="green";
    }
//    function zuoyou(){
//        var img = document.getElementsByTagName("img");
//        for(i = 0;i<img.length;i++){
//            img[i].style.display="none";
//        }
//    }
    function qing(){
        window.clearInterval(timer);
    }
    function hui(){
        timer = setInterval("lun()",2000);
    }

效果如下:(圖片拿不到)

技術分享圖片

左右點擊+小圓點+移動式:

#clmb{
                width: 480px;
                height: 300px;
                /*border: 1px solid red;*/
                margin-top: 100px;
                margin-bottom: 100px;
                overflow: hidden;
            }
            /*這是我要移動的圖片div*/
            #pick{
                width: 1500px;
                height: 300px;
                /*border: 1px solid blue;*/
            }
            .tup{
                width: 495px;
                height: 300px;
            }
            /*這是我小圓圈的屬性*/
            .roll{
                width: 20px;
                height: 20px;
                border: 1px solid white;
                border-radius:50% ;
                position: relative;
                background: black;
                opacity: 0.2;
            }
            .roll:hover{
                /*opacity: 0.9;*/
                cursor: pointer;
            }
            #roll_1{
                right: 34px;
                bottom: 135px;
            }
            #roll_2{
                right: 1px;
                bottom: 158px;
            }
            #roll_3{
                right: -32px;
                bottom: 180px;
            }
            /*這是我左右按鈕的屬性*/
            .butt{
                width: 50px;
                height: 50px;
                /*border: 1px solid red;*/
                color: white;
                font-size:50px;
                line-height: 50px;
                position: relative;
            }
            .butt:hover{
                color: black;
                opacity: 0.7;
                cursor: pointer;
            }
            #left{
                bottom: 335px;
                right: 211px;
            }
            #right{
                bottom: 388px;
                right: -213px;
            }
<!--這是我的輪播-->
        <div class="div_list">3、圖片輪播 加圖片下方圓點 加左右點擊</div>
        <div id="clmb">
            <div id="pick" style="margin-left: 0px; ">
                <img class="tup" src="1024x720 (2).jpg"/>
                <img class="tup" src="1024x720 (3).jpg"/>
                <img class="tup" src="1024x720 (4).jpg"/>
            </div>    
        </div>
        <div id="roll_1" class="roll" onclick="test_roll1()" onmouseover="qing()" onmouseout="chong()" style="opacity: 0.9;"></div>
        <div id="roll_2" class="roll" onclick="test_roll2()" onmouseover="qing()" onmouseout="chong()"></div>
        <div id="roll_3" class="roll" onclick="test_roll3()" onmouseover="qing()" onmouseout="chong()"></div>
        <div id="left" class="butt" onclick="test_left()" onmouseover="qing()" onmouseout="chong()">←</div>
        <div id="right" class="butt" onclick="test_right()" onmouseover="qing()" onmouseout="chong()">→</div>
var timer = setInterval("test_3()",2000);//這是我的輪播
    function qing(){
        window.clearInterval(timer);
    }
    function chong(){
        timer = setInterval("test_3()",2000);
    }
//    這是我第三題的思路
      var bs = 1;
     
//  圖片的切換和小圓點的變換
    function test_3(){
        var a = document.getElementById("pick");
        var b = document.getElementsByClassName("roll");
        var ml= a.style.marginLeft;
        ll=ml.substring(0,ml.length-2);
        dl=ll-500;
        if(dl ==-1500){
            dl=0;
        }
        a.style.marginLeft=dl+‘px‘;
        for (var i= 0;i<b.length;i++) {
            b[i].style.opacity="0.2";
        }
        b[bs].style.opacity="0.9";
        bs++;
        if (bs==3) {
            bs=0;
        }
        
    }
//    鼠標點擊左右
   var xx = 3;
    function test_left(){
        var a = document.getElementById("pick");
        var ml= a.style.marginLeft;
        ll=ml.substring(0,ml.length-2);
        ll=Number(ll);
        dl= ll + 500;
        if(dl == 500){
            dl=-1000;
        }
        dl=String(dl);
        a.style.marginLeft=dl+‘px‘;
        var b = document.getElementsByClassName("roll");
        for (var i= 0;i<b.length;i++) {
            b[i].style.opacity="0.2";
        }
        xx--;
        b[xx].style.opacity="0.9";
        
        if (xx == 0) {
            xx = 3;
        }
    }
    function test_right(){
        var a = document.getElementById("pick");
        var ml= a.style.marginLeft;
        ll=ml.substring(0,ml.length-2);
        dl=ll-500;
        if(dl == -1500){
            dl=0;
        }
        a.style.marginLeft=dl+‘px‘;
       var b = document.getElementsByClassName("roll");
        for (var i= 0;i<b.length;i++) {
            b[i].style.opacity="0.2";
        }
        b[bs].style.opacity="0.9";
        bs++;
        if (bs==3) {
            bs=0;
        }
    }
    function test_roll1(){
         document.getElementById("pick").style.marginLeft="0px";
         for (var i=0;i<3;i++) {
             document.getElementsByClassName("roll")[i].style.opacity="0.2";
         }
         document.getElementsByClassName("roll")[0].style.opacity="0.9";
    }
    function test_roll2(){
         document.getElementById("pick").style.marginLeft="-500px";  
         for (var i=0;i<3;i++) {
             document.getElementsByClassName("roll")[i].style.opacity="0.2";
         }
         document.getElementsByClassName("roll")[1].style.opacity="0.9";
    }
    function test_roll3(){
         document.getElementById("pick").style.marginLeft="-1000px"; 
         for (var i=0;i<3;i++) {
             document.getElementsByClassName("roll")[i].style.opacity="0.2";
         }
         document.getElementsByClassName("roll")[2].style.opacity="0.9";
    }

效果如下:

技術分享圖片

點左邊按鈕時:

技術分享圖片

點右邊按鈕時:

技術分享圖片

點中間小圓圈時:

技術分享圖片

輪播匯總:移動式、消失式、左右點擊+底下小圓圈