发表于: 2020-08-06 21:58:54

1 1163


今天完成的事情:

学习滚轮事件

学习拖拽


            window.onload = function () {
                /*
                    拖拽box1元素
                    流程1.当鼠标在被拖拽元素上按下时,开始拖拽onmousemove
                        2.当鼠标移动时被拖拽元素跟随鼠标移动onmousemove
                        3.当鼠标松开时,被拖拽元素固定在当前位置onmousemove
                */

                // 
                var box1 = document.getElementById("box1");
                // 为box1绑定一个鼠标按下事件
                box1.onmousemove = function () {
                    alert("鼠标按下,开始拖延~~")

                    // 为document
                    document.onmousemove = function (event) {
                        event = event || window.event;
                        // 获取鼠标的坐标
                        var left = event.clientX;
                        var top = event.clientY;

                    }
                };

            };


            window.onload = function () {
                /*
                    拖拽box1元素
                    流程1.当鼠标在被拖拽元素上按下时,开始拖拽onmousemove
                        2.当鼠标移动时被拖拽元素跟随鼠标移动onmousemove
                        3.当鼠标松开时,被拖拽元素固定在当前位置onmousemove
                */

                // 
                var box1 = document.getElementById("box1");
                // 为box1绑定一个鼠标按下事件
                box1.onmousemove = function () {
                    alert("鼠标按下,开始拖延~~")

                    // 为document
                    document.onmousemove = function (event) {
                        event = event || window.event;
                        // 获取鼠标的坐标
                        var left = event.clientX;
                        var top = event.clientY;

                    }
                };

            };



返回列表 返回列表
评论

    分享到