<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 火星華人
    好。
    主站蜘蛛池模板: 免费国产真实迷j在线观看| 又粗又大又黑又长的免费视频| 在线免费视频一区二区| 亚洲伊人久久大香线蕉在观| 久久青草免费91观看| 亚洲精品成人片在线播放 | 亚洲精品视频在线| 国产高清对白在线观看免费91| 亚洲精品国产精品乱码不卡 | 一级黄色免费网站| va亚洲va日韩不卡在线观看| 一级毛片免费在线播放| 亚洲男人av香蕉爽爽爽爽| 一级成人毛片免费观看| 亚洲一区二区三区偷拍女厕 | 亚洲激情校园春色| 亚洲一级毛片免费观看| 亚洲日韩av无码中文| 亚洲国产成人精品女人久久久| 成人免费网站久久久| 亚洲s色大片在线观看| 18女人水真多免费高清毛片| 亚洲成人一级电影| 在线中文高清资源免费观看| 国产亚洲蜜芽精品久久| 国产亚洲视频在线播放| 91久久精品国产免费一区| 亚洲中文字幕一二三四区苍井空 | h在线看免费视频网站男男| 亚洲va国产va天堂va久久| 18未年禁止免费观看| 亚洲av色香蕉一区二区三区| 亚洲国产精品视频| 久久青草免费91观看| 亚洲综合欧美色五月俺也去| 又黄又爽无遮挡免费视频| 国内永久免费crm系统z在线 | 免费va在线观看| 久久久国产精品福利免费| 亚洲AV无码国产精品色| 免费成人av电影|