分享html5的一個拖拽手法

來源:互聯網
上載者:User

標籤:query   log   ges   div   rem   use   span   body   always   

  就是這樣的效果:拖拽之前

  

    之後:

      

  上代碼:

<!DOCTYPE html><html lang="en">    <head>        <meta charset="UTF-8" />        <title> html5 drag and drop</title>        <style>            *[draggable=true] {                -moz-user-select:none;                -khtml-user-drag: element;                cursor: move;            }            *:-khtml-drag {                background-color: rgba(238,238,238, 0.5);            }            a {                text-decoration: none;                color: #000;                width:120px;                border: 3px dashed #999;                padding: 10px;                display:inline-block;                transition: all 1s;                position:absolute ;                top:10px;            }            .container {                position:relative;            }            a.move {                -webkit-transform:scale3d( 1.1, 1.1, 1.1 );            }            a:hover:after {                content: ‘ (drag me)‘;                color: green }        </style>    </head>    <body>        <div class="container">            <a draggable="true"  id="a1" style=‘left:0px;‘>one</a>            <a draggable="true"  id="a2" style=‘left:160px;‘>two</a>            <a draggable="true"  id="a3" style=‘left:320px;‘>three</a>            <a draggable="true"  id="a4" style=‘left:480px;‘>four</a>            <a draggable="true"  id="a5" style=‘left:640px;‘>five</a>        </div>        <script src="http://code.jquery.com/jquery-2.0.0.js"></script>        <script>            var origin, is_moving = false;            $(".container").find("a").on("drop",            function(e) {                var origin_pos = $(origin).position();                var target_pos = $(e.target).position();                $(origin).addClass("move").animate(target_pos, "fast",                    function() {                        console.log(this);                        $(this).removeClass("move");                    });                                $(e.target).addClass("move").animate(origin_pos, "fast",                function() {                    $(this).removeClass("move");                });            }).on("dragstart",            function(e) {                if (is_moving) {                    return false;                }                is_moving = true;                           e.originalEvent.dataTransfer.effectAllowed = ‘move‘;                origin = this;            }).on("dragover",            function(e) {                if (e.preventDefault) e.preventDefault(); //                is_moving = false;                e.originalEvent.dataTransfer.dropEffect = ‘move‘; //            });        </script>    </body></html>

每日一句:I always knew looking back on the tears would make me laugh, but I never knew looking back on the laughs would make me cry.

翻譯:我知道再回首時,那些眼淚想來可笑;卻不知再回眸時,那些歡聲笑語也能叫我潸然淚下。

分享html5的一個拖拽手法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.