Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery resizable centered div with grid producing unexpected results
    primarykey
    data
    text
    <p>I have a div that is centered on the page using css - margin: 0 auto; This is essential</p> <p>jQuery resizeable is connected to the div so that it can be resized horizontally. </p> <p>The 'grid' option for resizeable has also been added as other functions are triggered during resize and these functions were being called too many times without the grid option activated.</p> <p>i have also added a jquery position to the resizable div to keep it centered during resize otherwise when you drag the left edge it loses it's center position.</p> <p>The problem is that the mouse moves further and further away from the left edge the wider you drag the div to the left or right. The left/right edge of the div should always be snapping to the mouse position.</p> <p>Also the ui.size.width is reporting a value much higher than the actual width of the div.</p> <p>I have tried numerous fixes but nothing seems to work.</p> <p>Here's the code with a jsfiddle link below it:</p> <p>The HTML:</p> <pre><code>&lt;div id="container"&gt; &lt;div class="resize"&gt; Lorem &lt;br/&gt;ipsum &lt;br/&gt;dolor &lt;br/&gt;sit &lt;br/&gt;amet &lt;br/&gt;Consectetuer &lt;br/&gt;Lorem &lt;br/&gt;magna &lt;br/&gt;mi &lt;br/&gt;wisi &lt;/div&gt; &lt;/div&gt; &lt;div id="width-output"&gt;&lt;/div&gt; &lt;div id="ui-width-output"&gt;&lt;/div&gt; </code></pre> <p>The CSS:</p> <pre><code>#container { width:100%; background-color:#999999; } .resize { width:240px; margin:0 auto; background-color:#ccc; text-align:center; } #ui-width-output, #width-output { text-align:center; } </code></pre> <p>The jQuery:</p> <pre><code>$(document).ready(function () { $(".resize").resizable({ grid: [80, 80], handles: 'e, w', resize: function (event, ui) { ui.size.width += ui.size.width - ui.originalSize.width; var container = $('#container'); var position = $(this).position(); var container_position = container.position(); var top_position = position.top - container_position.top; var offset = 'center top+' + top_position; $(this).position({ of: $(container), my: offset, at: "center top", collision: "fit none" }); $('#width-output').html('actual width: ' + $(this).width() ); $('#ui-width-output').html('ui.size.width: ' + ui.size.width); } }); }); </code></pre> <p>I have created a test case so that all this makes more sense!</p> <pre><code>http://jsfiddle.net/bennyticklez/S5tN8/51/ </code></pre> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload