<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 火星華人
    好。
    主站蜘蛛池模板: 免费观看的a级毛片的网站| 亚洲日本VA中文字幕久久道具| 久久影视综合亚洲| 精品国产香蕉伊思人在线在线亚洲一区二区 | 国产精品成人免费综合| 亚洲午夜国产精品无码| 亚洲伊人色一综合网| 亚洲精品国产国语| 一个人看的免费观看日本视频www 一个人看的免费视频www在线高清动漫 | 久久精品免费一区二区喷潮| 国产a不卡片精品免费观看| 亚洲成a人片77777老司机| 国产午夜亚洲精品国产| 性盈盈影院免费视频观看在线一区| 亚洲大尺度无码无码专区| 亚洲精品动漫免费二区| 一级毛片在线免费看| 日本高清免费aaaaa大片视频| 图图资源网亚洲综合网站| 91福利免费视频| 亚洲国产电影av在线网址| 亚洲sss综合天堂久久久| 久久久久久免费一区二区三区| 国产美女做a免费视频软件| jzzijzzij在线观看亚洲熟妇| 中文字幕视频免费| 亚洲a视频在线观看| 91精品国产免费入口| 亚洲jjzzjjzz在线观看| 深夜国产福利99亚洲视频| 中文字幕亚洲精品无码| 免费人成视频x8x8入口| 亚洲av无码专区青青草原| 久久午夜免费视频| 亚洲一区二区影院| 一级特级aaaa毛片免费观看| 亚洲AV无码专区亚洲AV伊甸园| 岛国岛国免费V片在线观看 | 亚洲精品无码久久久| 色婷婷精品免费视频| 久久精品女人天堂AV免费观看|