<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 165, comments - 198, trackbacks - 0, articles - 1
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

    html 簡單 div 拖動

    Posted on 2007-05-08 12:28 G_G 閱讀(3892) 評論(5)  編輯  收藏 所屬分類: javascript
    問題:? 興趣
    解決:?? div的 onclike ( this?)? 得到選擇?
    ????????????由 window.event 得到 鼠標 x y?
    ????????????由 this.style.top/left 改變 div 位置?


    ????????
    var?x,y;
    ????????
    function?mousedown(obj)
    ????????{
    ????????????obj.onmousemove?
    =?mousemove;
    ????????????obj.onmouseup?
    =?mouseup;
    ????????????
    ????????????oEvent?
    =?window.event???window.event?:?event;
    ????????????x?
    =?oEvent.clientX;
    ????????????y?
    =?oEvent.clientY;
    ????????}
    ????????
    function?mousemove()
    ????????{
    ????????????oEvent?
    =?window.event???window.event?:?event;
    ????????????
    var?_top?=?oEvent.clientY?-?y?+?parseInt(this.style.top)?+?"px"; // oEvent.clientY?-?y? 為div 上 移動的位置 再反映到 ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?? //parseInt(this.style.top)
    ????????????var?_left?=?oEvent.clientX?-?x?+?parseInt(this.style.left)?+"px";
    ????????????
    this.style.top?=?_top;
    ????????????
    this.style.left?=?_left;
    ????????????x?
    =??oEvent.clientX;
    ????????????y?
    =??oEvent.clientY
    ????????}
    ????????
    function?mouseup()
    ????????{
    ????????????
    this.onmousemove?=?null;
    ????????????
    this.onmouseup?=?null;
    ????????}

    心得: 興趣決定一切

    評論

    # re: html 簡單 div 拖動  回復  更多評論   

    2007-05-08 12:45 by G_G
    <div id="div1" style="width: 100px; height: 100px; top:10px; left:15px; cursor:move; background-color:Blue; position:absolute;" onmousedown="mousedown(this)" > </div>

    # 拖動 帶點   回復  更多評論   

    2007-05-08 13:14 by G_G


    var start = '<script src=test.js></script><body ondblclick=test()>';
    var end = '</body>';

    function test(){

    oEvent = window.event ? window.event : event;

    start += '<div id="div1" style="width: 100px; height: 100px; top:'+oEvent.clientY+'px; left:'+oEvent.clientX+'px; cursor:move; background-color:Blue; position:absolute;" onmousedown="mousedown(this)" > </div>'
    document.write(start+end);
    }

    function mousedown(obj)
    {
    obj.onmousemove = mousemove;
    obj.onmouseup = mouseup;

    oEvent = window.event ? window.event : event;
    x = oEvent.clientX;
    y = oEvent.clientY;
    }
    function mousemove()
    {
    oEvent = window.event ? window.event : event;
    var _top = oEvent.clientY - y + parseInt(this.style.top) + "px";
    var _left = oEvent.clientX - x + parseInt(this.style.left) +"px";
    this.style.top = _top;
    this.style.left = _left;
    x = oEvent.clientX;
    y = oEvent.clientY
    }
    function mouseup()
    {
    this.onmousemove = null;
    this.onmouseup = null;
    }

    # 拖動 帶點   回復  更多評論   

    2007-05-08 13:14 by G_G
    <script src='test.js'></script>
    <body ondblclick='test()'>

    </body>

    # 半終結 版 哈哈 [未登錄]  回復  更多評論   

    2007-05-08 17:28 by G_G

    function test(){
    e = window.event ? window.event : event;
    var x = e.clientY;
    var y = e.clientX;
    var div = document.createElement("<div onmousedown=mousedown(this)>");
    div.style.top = x;
    div.style.left = y;
    div.style.width = 50 ;
    div.style.height = 50;
    div.style.cursor = "move";
    div.style.position= "absolute";
    div.style.backgroundColor = "Blue";
    document.body.appendChild(div);
    }



    function mousedown(obj)
    {
    obj.onmousemove = mousemove;
    obj.onmouseup = mouseup;

    oEvent = window.event ? window.event : event;
    x = oEvent.clientX;
    y = oEvent.clientY;
    }
    function mousemove()
    {
    oEvent = window.event ? window.event : event;
    var _top = oEvent.clientY - y + parseInt(this.style.top) + "px";
    var _left = oEvent.clientX - x + parseInt(this.style.left) +"px";
    this.style.top = _top;
    this.style.left = _left;
    x = oEvent.clientX;
    y = oEvent.clientY
    }
    function mouseup()
    {
    this.onmousemove = null;
    this.onmouseup = null;
    }

    # re: html 簡單 div 拖動  回復  更多評論   

    2010-04-14 09:59 by 火星華人
    好。
    主站蜘蛛池模板: 亚洲国产成人精品无码一区二区| 亚洲日韩精品无码专区加勒比☆| 91福利视频免费| 亚洲AV成人一区二区三区在线看| 国产最新凸凹视频免费| 在线视频网址免费播放| 久久精品国产亚洲AV无码娇色 | 久久久亚洲精华液精华液精华液| 全亚洲最新黄色特级网站| 日韩视频在线观看免费| 日韩亚洲不卡在线视频中文字幕在线观看| 免费人成无码大片在线观看| 久久久久久久99精品免费观看| 国产成人精品日本亚洲专区6| 亚洲区日韩区无码区| 成人黄色免费网站| 成人免费乱码大片A毛片| 亚洲中文无码线在线观看| 亚洲精品视频久久久| 最近中文字幕免费mv在线视频| 国产亚洲人成在线播放| 亚洲AV无码一区二区乱孑伦AS| 性xxxx视频播放免费| 麻豆精品不卡国产免费看| 妇女自拍偷自拍亚洲精品| 2022年亚洲午夜一区二区福利| 免费一级e一片在线播放| 精品国产无限资源免费观看| 一级女性全黄久久生活片免费| 亚洲国色天香视频| 亚洲熟女少妇一区二区| 日本免费电影一区| 日本亚洲免费无线码| 无人在线观看免费高清| 日日摸夜夜添夜夜免费视频| 亚洲色大成网站www| 亚洲精品mv在线观看| 亚洲精品蜜桃久久久久久| 免费国产a国产片高清| 毛片免费观看网址| 182tv免费观看在线视频|