进度条的拖拽

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        *{margin: 0;padding: 0;}
        .father{width:500px;height:30px;border:1px solid #ccc;margin:50px auto 0;position:relative;}
        .son{width:30px;height:30px;background: #f00;position:absolute;top:0;left:0;}
        .brother{width:500px;height:480px;background: #f23;margin:20px 0 0 280px;}
    </style>
</head>
<body>
    <div class="father" id="father">
        <div class="son" id="son"></div>
    </div>
    <div class="brother" id="brother"></div>

    <script>
        var oSon = document.getElementById('son');
        var oF = document.getElementById('father');
        var oB = document.getElementById('brother');
        var W = oF.offsetWidth-oSon.offsetWidth
        oSon.onmousedown=function(ev){
            var evt = ev||event;
            var disX = evt.offsetX;
            var disY = evt.offsetY;
            document.onmousemove=function(ev){
                var evt=ev||event;
                var mX = evt.clientX;
                var mY = evt.clientY;
                var l=mX-oF.offsetLeft-disX;
                // var t=mY-oF.offsetTop-disY;

                if(l<=0){
                    l=0;
                }else if(l>=W){
                    l=W;
                }
                oSon.style.left=l+"px";

        
            var w=500*l/W;    
            oB.style.width=w+"px";
            oB.style.height=480*l/W+"px";

                // oSon.style.top=t+"px";
                return false;
            }
            document.onmouseup=function(){
                document.onmousemove=null;
            }
        }
    </script>
</body>
</html>

 

加油 !

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值