Chinaunix首页 | 论坛 | 博客
  • 博客访问: 465626
  • 博文数量: 226
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2111
  • 用 户 组: 普通用户
  • 注册时间: 2014-06-20 09:02
个人简介

web web web

文章分类

全部博文(226)

文章存档

2020年(2)

2019年(1)

2018年(3)

2017年(26)

2016年(57)

2015年(60)

2014年(77)

我的朋友

分类: Web开发

2014-09-16 09:40:02

function dragElement(id) {
    this.dom = document.getElementById(id);
    this.isMouseDown = false;
    this.pos = null;
}
dragElement.prototype = {
     init: function() {
            var _this = this;
            this.moveDom.onmousedown = function(e) {
            _this.isMouseDown = true;
            _this.getPos(e);
        document.onmouseup = function() {
            _this.isMouseDown = false;
            document.onmousemove = null;
            document.onmouseup = null;
        };
        document.onmousemove = function(e) {
            _this.move(e);
         };
    },
    getPos: function(e) {
        e = e || window.event;
        this.pos = {
            x: e.clientX - this.dom.offsetLeft,
            y: e.clientY - this.dom.offsetTop
        };
    },
    move: function(e) {
        var _this = this;
        this.dom.style.opactiy
        if (this.isMouseDown) {
            this.dom.style.left = e.clientX - this.pos.x + "px";
            this.dom.style.top = e.clientY - this.pos.y  + "px";
        }
    }
}
var d = new dragElement("m");
d.init();
阅读(358) | 评论(0) | 转发(0) |
0

上一篇:js原型

下一篇:JS事件委托

给主人留下些什么吧!~~