zoukankan      html  css  js  c++  java
  • 图片上下滑动(鼠标点击才动)

    实现代码:

    HTML+CSS:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>Document</title>
    <style>
        *{margin: 0px;padding: 0px;}
        body{background-color: #eee;padding: 100px;}
        a{text-decoration: none;}
        b{display: block;height: 40px;width: 40px;line-height: 40px;border-radius: 40px;background-color: #117b1c;color: #fff;text-align: center;cursor: pointer;}
        #box{position: relative;height: 312px;width: 92px;padding: 10px;border: 1px solid #ccc;overflow: hidden;}
        #box ul{position: absolute;top: 0;left: 0;}
        #box ul li{list-style: none;height: 100px;width: 100px;padding: 5px;}
        #box ul li a{display: block;width: 100px;height: 100px;border: 1px solid #000;}
        #box ul li.no1 a{background-color: #99CC33;}
        #box ul li.no2 a{background-color: #FF6666;}
        #box ul li.no3 a{background-color: #336699;}
        #box ul li.no4 a{background-color: #99CCCC;}
    </style>
    </head>
    <body>
        <b></b>
        <div id="box">
            <ul>
                <li class="no1"><a href="javascript:;'">111</a></li>
                <li class="no2"><a href="javascript:;'">222</a></li>
                <li class="no3"><a href="javascript:;'">333</a></li>
                <li class="no4"><a href="javascript:;'">444</a></li>
            </ul>
        </div>
        <b></b>
    </body>
    </html>

    js:

    <script>
        window.onload=function(){
            var oBox = document.getElementById('box');
            var oUl = oBox.getElementsByTagName('ul')[0];
            var aLi = oUl.getElementsByTagName('li');
            var aBtn = document.getElementsByTagName('b');
            var timer = null;
            var iSpeed = -5;
    
            oUl.innerHTML+=oUl.innerHTML;
    
            aBtn[0].onmousedown=function(){
                iSpeed = -5;
                timer = setInterval(doMove,30);
            };
    
            aBtn[0].onmouseup=function(){
                clearInterval(timer);
            };
    
            aBtn[1].onmousedown=function(){
                iSpeed = 5;
                timer = setInterval(doMove,30);
            };
    
            aBtn[1].onmouseup=function(){
                clearInterval(timer);
            };
    
            function doMove(){
                oUl.style.top = oUl.offsetTop + iSpeed +'px';
    
                if(oUl.offsetTop < -oUl.offsetHeight/2){
                    oUl.style.top = '0';
                }
                else if(oUl.offsetTop > 0){
                    oUl.style.top = -oUl.offsetHeight/2 + 'px';
                }
            };
    
        }
    </script>

    效果如下图所示:

    高否?富否?帅否? 否? 滚去学习!
  • 相关阅读:
    1.5.2 在IIS上配置ASP.NET(转)
    数据结构二叉树的基本编码(原创)
    真正的AmChart破解教程和RadarChart使用(转)
    C#遍历文件中的文件或者文件夹(转)
    [Android]在代码中创建布局
    [AS]AIR 中获取本地 IP API
    [Android][转]Android获取网页数据的方法总结
    [AS][iOS]AIR应用在iOS中,home键退出
    [Android]ListView学习(一)
    [Android]TextView 单行文本过长显示的属性
  • 原文地址:https://www.cnblogs.com/baixc/p/3435178.html
Copyright © 2011-2022 走看看