Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Don't keep aspect ratio with jQuery resizable while holding shift

I'm resizing a div with jQuery resizable and I only want to resize its height.

I managed to only resize while dragging bottom helper :

$('div').resizable({
   handles: 's',
});

But if I hold shift key, width is changing. See http://jsfiddle.net/6p20qjmr/3/

How can I disable this behavior?

Edit: The div container width may change after initial resizable call.

like image 228
Hugo H Avatar asked Sep 28 '22 20:09

Hugo H


1 Answers

$(function() {
    var $elt = $(".resize");
    var width = $elt.width();
   $elt.resizable({
       handles: 's',
       maxWidth: width,
       minWidth: width
    });
});

This may not be the best solution, but I am not super familiar with JQuery UI's resizable functionality. I'm not even sure why holding shift changes the functionality. If you could explain that, I may be able to provide a better solution that seems less hacky.

Fiddle: http://jsfiddle.net/6p20qjmr/

like image 140
thatidiotguy Avatar answered Oct 10 '22 02:10

thatidiotguy