<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 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

    html 簡單 div 拖動

    Posted on 2007-05-08 12:28 G_G 閱讀(3892) 評論(5)  編輯  收藏 所屬分類: javascript
    問題:? 興趣
    解決:?? div的 onclike ( this?)? 得到選擇?
    ????????????由 window.event 得到 鼠標(biāo) 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 拖動  回復(fù)  更多評論   

    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>

    # 拖動 帶點(diǎn)   回復(fù)  更多評論   

    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;
    }

    # 拖動 帶點(diǎn)   回復(fù)  更多評論   

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

    </body>

    # 半終結(jié) 版 哈哈 [未登錄]  回復(fù)  更多評論   

    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 拖動  回復(fù)  更多評論   

    2010-04-14 09:59 by 火星華人
    好。
    主站蜘蛛池模板: 全部免费a级毛片| 亚洲v高清理论电影| 日韩免费的视频在线观看香蕉| 色婷婷六月亚洲婷婷丁香| 最新中文字幕电影免费观看| 一级毛片免费不卡| 亚洲精品中文字幕无码AV| 国产大片免费观看中文字幕| 三年片在线观看免费| 亚洲中文字幕无码中文字| 中文字幕第一页亚洲| 国色精品卡一卡2卡3卡4卡免费| 色九月亚洲综合网| 91天堂素人精品系列全集亚洲| 日韩在线视频免费看| 成人性生交大片免费看中文| 亚洲国产精品精华液| 亚洲国产成人久久精品动漫 | 日韩在线天堂免费观看| 中文字幕免费不卡二区| 亚洲av永久无码天堂网| 亚洲成a人片77777老司机| 免费永久在线观看黄网站| 亚洲免费人成视频观看| 久久免费视频一区| 久久久久久亚洲av无码蜜芽| 亚洲欧洲国产精品你懂的| 亚洲欧洲日产国码高潮αv| 免费无码精品黄AV电影| 免费av一区二区三区| 黄色免费网址大全| 亚洲三级视频在线| 亚洲AV永久精品爱情岛论坛| 亚洲A∨午夜成人片精品网站| 99精品全国免费观看视频| 99热在线免费观看| 东方aⅴ免费观看久久av| 国产伦精品一区二区免费| 精品亚洲成A人在线观看青青| 亚洲人成综合网站7777香蕉| 亚洲欧洲国产日韩精品|