我在东北烤地瓜

I am kaodigua I am chirourou I am qiaodaima

导航

简单整一下元素拖拽

<script type="text/javascript">
    
    var oDiv = document.getElementById('info1');
    
    oDiv.onmousedown = function (env) {
        var env = env||window.event;

        var disX = env.offsetX;
        var disY = env.offsetY;

        document.onmousemove = function(env){
        var env = env||window.event;

        oDiv.style.left = env.clientX - disX+'px';
        oDiv.style.top = env.clientY -disY+'px';
        }
        document.onmouseup =function(){

            document.onmousemove = null;
        }
    }
    


</script>
<style>
        #info1{

            width: 200px;
            height: 200px;
            background: #c599af;
            position: absolute;
            cursor: move;
        }
    </style>

<body>
    <div id="info1"></div>
</body>

 

posted on 2020-07-24 08:25  我在东北烤地瓜  阅读(117)  评论(0编辑  收藏  举报