<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免费| 免费毛片在线视频| 亚洲日韩精品无码AV海量| 最新中文字幕免费视频| 亚洲日本va一区二区三区| 大香人蕉免费视频75| 日韩欧美亚洲国产精品字幕久久久| 日本一区二区三区免费高清| 亚洲砖码砖专无区2023| 日本最新免费不卡二区在线| 精品视频免费在线| 亚洲色图综合在线| 日本高清高色视频免费| 亚洲视频免费在线播放| 最新中文字幕免费视频| 老司机午夜性生免费福利| 国产亚洲美日韩AV中文字幕无码成人 | 日韩亚洲精品福利| 精品无码一级毛片免费视频观看| 中文国产成人精品久久亚洲精品AⅤ无码精品 | 国产男女猛烈无遮挡免费视频网站| 另类图片亚洲校园小说区| 亚洲色欲色欲www在线丝| 91精品国产免费久久国语蜜臀| 91丁香亚洲综合社区| www.亚洲色图.com| 久久成人无码国产免费播放| 亚洲欧洲日韩极速播放| 亚洲视频在线精品| 中文字幕视频免费| 国产成人精品亚洲一区| 亚洲Av无码专区国产乱码DVD | 一本久久免费视频| 亚洲欧洲日本国产| 国产乱辈通伦影片在线播放亚洲| 国产精品免费无遮挡无码永久视频| 亚洲一本到无码av中文字幕| 亚洲熟妇中文字幕五十中出|