<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
            position: absolute;
            left: 10px;
            top: 10px;
            width: 100px;
            height: 100px;
            background-color: orange;
            cursor: pointer;
    <div class="box">


    <script src="../jqueryFile/jquery-3.4.1.js"></script>
        $(".box").mousedown(function (event){
            // 拖动效果要在鼠标移动事件中绑定
            var x = event.pageX - $(this).offset().left;
            var y = event.pageY -$(this).offset().top;
            $(this).mousemove(function (e){
                console.log("x = " + e.pageX + "y = " + e.pageY);
                    left:(e.pageX - x),
                    top:(e.pageY - y)
        }).mouseup(function (){



Last modification:July 8th, 2019 at 03:04 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment