2012-08-24 16 views
1

我有兩個可調整大小的元素,我需要它們調整大小同時維護網格。看起來這兩個選項不能一起工作。有任何想法嗎?jQuery UI可調整大小 - 與網格同步

演示:http://jsfiddle.net/CbYtT/2/ (嘗試調整水平)

$(function() { 

    $("#this").resizable({ 
     alsoResize: "#that", 
     grid: 100 

    }); 

    $("#that").resizable({ 
     alsoResize: "#this", 
     grid: 100 
    }); 

}); 
+0

你可以請發表您的HTML/CSS還的工作版本? – Vikram

+0

當然。 http://jsfiddle.net/CbYtT/2/ –

回答

5

這不是很漂亮,但它的工作原理。

$("#this").resizable({ 
     handles: "e", 
     resize: function(event, ui) { 
      $("#that").width($(this).width()); 
      $("#that").height($(this).height()); 
     }, 
     stop: function(event, ui) { 
      $("#that").width($(this).width()); 
      $("#that").height($(this).height()); 
     }, 
     grid: 100 
    }); 

    $("#that").resizable({ 
     handles: "e", 
     resize: function(event, ui) { 
      $("#this").width($(this).width()); 
      $("#this").height($(this).height()); 
     }, 
     stop: function(event, ui) { 
      $("#this").width($(this).width()); 
      $("#this").height($(this).height()); 
     }, 
     grid: 100 
    }); 

您的JS提琴

http://jsfiddle.net/Robodude/CbYtT/3/

+1

因此,最後在jQuery UI中的「alsoResize」選項不尊重網格......你的答案是有效的。我已經刪除了「停止」,因爲它不是必需的:http://jsfiddle.net/CbYtT/4/謝謝! –

相關問題