簡體   English   中英

jQuery-ui 可調整大小:拖動元素時調整大小的問題

[英]jQuery-ui resizable: problem with resize when element is dragged

當我拖動一個div並調整它的大小時,該div會返回到它原來的 position ......你能幫我解決這個問題或糾正我的代碼中的錯誤嗎?

在此先感謝,這是我的代碼:

 $(function() { // There's the gallery and the trash var $job = $("#testblocks"), $ressource = $(".ressource"); // Let the gallery items be draggable $("div", $job).draggable({ revert: "invalid", containment: ".containment-wrapper", //helper: "clone", cursor: "move", grid: [91, 91], refreshPositions: true, drag: function() { var offset = $(this).offset(); var xPos = offset.left; var yPos = offset.top; $('#posX').text('x: ' + xPos.toFixed(2)); $('#posY').text('y: ' + yPos.toFixed(2)); } }); $(".drag").resizable({ handles: 'e, w', grid: 91, containment: ".containment-wrapper" }); $ressource.droppable({ accept: "#testblocks > div, .ressource div", classes: { "ui-droppable-active": "ui-state-highlight" }, over: function(event, ui) { $(ui.draggable).draggable({ grid: [91, 50] }); }, out: function(event, ui) { //alert(); $(ui.draggable).draggable("option", "grid", false); } /*, drop: function (event, ui) { $(ui.draggable).appendTo($(this)); }*/ }); $job.droppable({ accept: ".ressource div", classes: { "ui-droppable-active": "custom-state-active" }, drop: function(event, ui) { $(ui.draggable).appendTo($job); } }); });
 .drag { height: 49px; width: 88px; text-align: center; z-index: 999; padding: 0; margin: 0; } td { border: 1px solid black; height: 50px; width: 160px; padding: 0; margin: 0; } th { border: 1px solid black; height: 50px; width: 180px; padding: 0; margin: 0; } tr { border: 1px solid black; height: 50px; width: 100%; padding: 0; margin: 0; }.basr { height: 150px; padding: 0; margin: 0; }.masterContent { padding: 0; margin: 0; }
 <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <table cellspacing="0" style="border:1px solid black; text-align:center;position:relative;"> <tbody style="border:1px solid black;"> <tr style="border:1px solid black;"> <th style="border:1px solid black;"></th> <th style="border:1px solid black;">12am</th> <th style="border:1px solid black;">1am</th> <th style="border:1px solid black;">2am</th> </tr> <tr> <th>Ressource 1</th> <td colspan="3" rowspan="2" class="masterContent" style="position:relative;"> <table cellspacing="0" style="width:100%;" class="containment-wrapper"> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <tr class="basr"> <td colspan="6" id="testblocks"> <div class="ui-widget-content ui-corner-tr drag"> <span id="posX"></span><br/> <span id="posY"></span> </div> </td> </tr> </table> <div style="top:0;left:0;position:absolute;width:100%;height:50px;padding:0;margin:0 auto;" class="ressource"></div> </td> </tr> <tr class="basr"> <th>bac à sable</th> </tr> </tbody> </table>

更改$jobaccept選項,這樣td#testblocks可以接受可拖動的 div。

$job.droppable({
    accept: ".drag",
    classes: {
      "ui-droppable-active": "custom-state-active"
    },
    drop: function(event, ui) {
      $(ui.draggable).appendTo($job);
    }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM