• 滑动条


    <!DOCTYPE html>
    <html lang="en">
    <head>
         <meta charset="UTF-8">
         <title>滑动条</title>
         <style type="text/css">
             .box{
                400px;
                height: 8px;
                background-color: #ccc;
                margin: 100px auto;
                position: relative;
             }
             .box .bar{
                10px;
                height: 20px;
                background-color: #369;
                position: absolute;
                top: -6px;
                left: 0;
                cursor: pointer;
             }
             .box .mask{
                0px;
                height: 100%;
                background-color: #369;
             }
         </style>
    </head>
    <body>
         <div class="box" id="box">
             <div class="bar" id="bar"></div>
             <div class="mask" id="mask"></div>
         </div>
         <script type="text/javascript">
             function $(id){
                return document.getElementById(id);
             }
             var bar = $('bar');
             //onclick事件,是鼠标点击下去,然后松开手才会触发
             //onmousedown事件,是鼠标点击下去就触发
             bar.onmousedown = function(event){
                var evt = event || window.event;
                var mLeft = evt.clientX - bar.offsetLeft;
                document.onmousemove = function(event){
                    var evt = event || window.event;
                    var barX = evt.clientX - mLeft;
                    if(barX < 0){
                        barX = 0;
                    }
                    if(barX > (bar.parentNode.offsetWidth - bar.offsetWidth)){
                        barX = (bar.parentNode.offsetWidth - bar.offsetWidth)
                    }
                    bar.style.left = barX + 'px';
                    $('mask').style.width = barX + 'px';
                    window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
                }
                //一定要在bar.onmousedown内部注册,否则不起作用
                document.onmouseup = function(){
                    document.onmousemove = null;
                }
             }
         </script>
    </body>
    </html>
  • 相关阅读:
    Git版本控制使用方法入门教程
    github 与git 使用 及配置
    IOS ASI http 框架详解
    block 理解及 简单回调
    IOS在Xcode 4.x以上如何 创建 和 添加 静态库
    dispatch queues GCD
    理解UIApplication(转)
    android 标签对应的代码怎么写alignParentRight、marginRight
    Android 资源文件的命名规范问题
    输入法弹出,屏幕自动适应
  • 原文地址:https://www.cnblogs.com/mmit/p/11258116.html
Copyright © 2020-2023  润新知