请选择 进入手机版 | 继续访问电脑版

弘帝企业智能建站系统交流平台

 找回密码
 立即注册
查看: 1464|回复: 0

ES6_拖拽

[复制链接]
发表于 2020-12-20 09:11:46 | 显示全部楼层 |阅读模式
<div id="box"></div>
CSS:
div {
        width:100px;
        height:100px;
        border-radius:50%;
        position:absolute;
}
JS:
class Pen {
    constructor() {
        document.onmousedown = this.down.bind(this);
    }
    down() {
        document.onmousemove = this.move.bind(this);
        document.onmouseup = this.up.bind(this);
    }
    move(e) {
        var e = e || event;
        var div = document.getElementById("box");
        div.style.cssText = "left:" + e.clientX + "px; top:" + e.clientY + "px;";
        div.style.background = "blue";
    }
    up() {
        document.onmousemove = null;
        document.onmouseup = null;
    }
}

new Pen();

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|弘帝企业智能建站系统 ( 皖ICP备07503252号 )

GMT+8, 2024-4-18 10:13 , Processed in 0.097668 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表