zoukankan      html  css  js  c++  java
  • 图片轮播

    向左轮播可以,再向右的话就需要重新定义距离了,不知道除了marginleft还有没有其他表示距离的代码 ,再试试!

    <style>
    * {
    margin: 0px;
    padding: 0px;
    }

    .kuang{
    margin: 150px;
    620px;
    height: 380px;
    /*border: 5px solid black;*/
    position: relative;
    }

    .p{
    620px;
    height: 380px;
    background-color: red;
    float: left;
    color: white;
    font-size: 100px;
    text-align: center;
    line-height: 380px;
    }

    .da{
    2480px;
    height: 380px;
    }

    .left,.right {
    20px;
    height: 380px;
    font-size: 30px;
    line-height: 380px;
    text-align: center;
    background-color: black;
    color: white;
    opacity: 0.5;
    position: absolute;
    top: 0px;
    }

    .left{
    left: 0px;
    }

    .right{
    right: 0px;
    }

    .left:hover,.right:hover {
    cursor: pointer;
    opacity: 0.3;
    }

    </style>
    </head>
    <body>
    <div class="kuang">
    <div class="left"><</div>
    <div class="right">></div>
    <div class="da">
    <div class="p" style="background-color: blueviolet;"></div>
    <div class="p" style="background-color: darkturquoise;"></div>
    <div class="p" style="background-color: yellow;"></div>
    <div class="p" style="background-color: green;"></div>
    </div>
    </div>
    </body>
    </html>
    <script>
    left=document.getElementsByClassName("left")[0];
    right=document.getElementsByClassName("right")[0];
    da=document.getElementsByClassName("da")[0];

    arr=[];
    s=1;

    left.onclick=function(){
    arr.push(window.setInterval("moveleft()",5));
    }
    function moveleft(){

    if(da.offsetLeft==-620*s){
    clearall();
    s++;
    }else{
    da.style.marginLeft=da.offsetLeft-20+"px";
    }
    }
    function clearall(){
    for(i in arr){
    window.clearInterval(arr[i])
    }
    }


    arr2=[];
    a=1;

    right.onclick=function(){
    arr2.push(window.setInterval("moveright()",5));
    }
    function moveright(){

    if(da.offsetLeft==620*a){
    clearal();
    a++;
    }else{
    da.style.marginLeft=da.offsetLeft+20+"px";
    }
    }
    function clearaal(){
    for(x in arr2){
    window.clearInterval(arr2[x])
    }
    }

    </script>

    代码不是很完美,日后好了之后再发一遍把

  • 相关阅读:
    IIC时序和24C02读写字节时序
    Labview-vi的可重入性
    Labview笔记-创建自定义控件
    非院校科研机构如何查阅下载文献?
    【转】经典的图像去噪算法NLM和BM3D算法
    【转载】计算机科学最重要的32个算法
    图像存储方式
    二维物体形状识别方法比较
    论static关键词
    论引用
  • 原文地址:https://www.cnblogs.com/m110/p/7617966.html
Copyright © 2011-2022 走看看