Skip to content Skip to sidebar Skip to footer

Jquery Ui Resizable Does Not Support Position: Fixed; Any Recommendations?

JQuery UI's .resizable function does not support position: fixed; elements. The moment you try to resize them it switches their position attribute to absolute. Any recommended fixe

Solution 1:

To get over this problem I wrapped the .resizable() block with the .draggable() block:

<div id="draggable-dealie">
    <div id="resizable-dealie">
    </div>
</div>

the corresponding js:

$("#draggable-dealie").draggable();
$("#resizable-dealie").resizable();

and ensure you have the property position:fixed !important; set in the #draggable-dealie CSS:

#draggable-dealie {
    position:fixed !important;
    width:auto;
    height:auto;
}

I have a demonstration at: http://jsfiddle.net/smokinjoe/FfRRW/8/

Solution 2:

If, like me, you have a fixed div at the bottom of the page, then you can just add !important to these css rules to make it stick at the bottom :

.fixed {
  position: fixed !important;
  top: auto !important;
  bottom: 0!important;
  left: 0;
  right: 0;
}

And just make it resizable by its north border :

$('.fixed').resizable({
  handles: "n"
});

Solution 3:

Simply force position:fixed on the element when resizing starts and when resizing stops.

$(".e").draggable().resizable({
   start: function(event, ui) {
      $(".e").css("position", "fixed");
   },
   stop: function(event, ui) {
      $(".e").css("position", "fixed");
   }
});

JSFiddle: http://jsfiddle.net/5feKU/

Solution 4:

No beauty but how about saving the position (top and left) in separate vars on the start of the resize (I think the method is called "start")?

UPDATE (Thank you for the comment... The event fires too late): As JqueryUI generates a second object "ui" on making a object resizable it gives that ui-object a field: ui.originalPosition... That should be the position of the fixed element before the resizing...

Solution 5:

Here's the solution I came up with, it's a little more code than I'd like, but it fixes the problem:

$("#test").resizable({stop:function(e, ui) {
    var pane = $(e.target);
    var left = pane.attr("startLeft");
    var top = pane.attr("startTop");
    pane.css("position", "fixed");
    pane.css("top", top);
    pane.css("left", left);
}});
$("#test").draggable({create: function(e, ui) {
    var pane = $(e.target);
    var pos = pane.position();
    pane.attr("startLeft", pos.left + "px");
    pane.attr("startTop", pos.top + "px");
}, stop: function(e, ui) {
    var pane = $(e.target);
    pane.attr("startLeft", ui.position.left + "px");
    pane.attr("startTop", ui.position.top + "px");
}});

This stores the top and left position in the html element (needs xhtml doctype to be valid) and uses that information to set the position at the end of the resizing event.

Post a Comment for "Jquery Ui Resizable Does Not Support Position: Fixed; Any Recommendations?"