鼠标拖动div

  var rDrag = {

            o: null,

            init: function (o) {
                o.onmousedown = this.start;
            },
            start: function (e) {
                var o;
                e = rDrag.fixEvent(e);
                e.preventDefault && e.preventDefault();
                rDrag.o = o = this;
                o.x = e.clientX - rDrag.o.offsetLeft;
                o.y = e.clientY - rDrag.o.offsetTop;
                document.onmousemove = rDrag.move;
                document.onmouseup = rDrag.end;
            },
            move: function (e) {
                e = rDrag.fixEvent(e);
                var oLeft, oTop;
                oLeft = e.clientX - rDrag.o.x;
                oTop = e.clientY - rDrag.o.y;
                rDrag.o.style.left = oLeft + 'px';
                rDrag.o.style.top = oTop + 'px';
            },
            end: function (e) {
                e = rDrag.fixEvent(e);
                rDrag.o = document.onmousemove = document.onmouseup = null;
            },
            fixEvent: function (e) {
                if (!e) {
                    e = window.event;
                    e.target = e.srcElement;
                    e.layerX = e.offsetX;
                    e.layerY = e.offsetY;
                }
                return e;
            }
        }

 window.onload = function () {

 var obj = document.getElementById('divUpdate');
            rDrag.init(obj);

}

 

 

html代码:

 <form id="form1" runat="server">

    <div id="divUpdate" style="display: none; width: 300px; float: right;" class="white_content">
        <div class="tc_content">
            <div class="tc_info">
                <table width="100%" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#F1F1F1">
                    <tr>
                        <td align="right" bgcolor="#F9F9F9">
                            传感器名称:
                        </td>
                        <td align="left" bgcolor="#F9F9F9">
                            <select id="EqpName" οnchange="showListSelfNum(document.getElementById('EqpName').value)">
                                <option></option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td align="right" bgcolor="#F9F9F9">
                            传感器编号:
                        </td>
                        <td align="left" bgcolor="#F9F9F9">
                            <select id="EqpselfNum">
                                <option></option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td align="right" bgcolor="#F9F9F9">
                            设备X位置:
                        </td>
                        <td align="left" bgcolor="#F9F9F9">
                            <input type="text" class="dj_input01" size="15" runat="server" id="uXlocation" />
                        </td>
                    </tr>
                    <tr>
                        <td align="right" bgcolor="#F9F9F9">
                            设备Y位置:
                        </td>
                        <td align="left" bgcolor="#F9F9F9">
                            <input type="text" class="dj_input01" size="15" runat="server" id="uYlocation" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <input type="button" style="position: absolute; left: 70px;" id="btnUpSure" class="but01"
                                value="确定" />
                        </td>
                        <td>
                            <input type="button" style="position: absolute; left: 170px;" id="btnUpCancel" class="but01"
                                value="取消" />
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>

<form>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值