I have multiple divs with absolute positioning on a page, all with the same class.
Is there a way to restrict resizing each of the divs so that they do not overlap any of the other divs of the same class?
You can use the resize event from jQuery-ui resizable. Calculate if your element is about to pass another elements top/left positions and prevent it from doing so by setting the maxWidth to it's current width.
Source:
Prevent jQuery UI resizable element from covering another element?
Related
I am trying to use jQuery Ui to drag an overflowing child div, this div does drag but further than I like. I only want it to drag the scroll-able amount.
Hopefully this codepen will show you want I mean -
http://codepen.io/seanjacob/pen/RKKEyO
$(".box").draggable({axis: "x"});
All widths will be responsive. It doesn't have to be a jQuery Ui solution.
This is exactly what I was looking for -
http://qnimate.com/javascript-scroll-by-dragging/
github: https://github.com/asvd/dragscroll
It just drags the scrollbar, nothing more or less and is responsive.
I have an image at http://jsfiddle.net/3GWL2/2/ that I want to make draggable and resizable:
I'm experimenting with three lines:
1. //$('#clown').draggable();
2. //$('#clown').draggable().resizable();
3. //$('#clown').resizable().draggable();
If I only uncomment line 1 the image is draggable fine.
If I only uncomment line 2 the image is resizable but it's not draggable.
If I only uncomment line 3, the image is draggable, but but only within the original size, and the image is resizable.
Apparently resizable and draggable are far from independent of each other. Could someone explain what's going on here?
Thanks
jQuery UI's .resizable() makes your element resizable by adding a ui-wrapper div around your element that is initially the same size as your element, and setting your element to fill both height and width. Making your element draggable only allows it to be dragged within the ui-wrapper div.
If you want to be able to both drag and resize, apply .resizable() first, then make the wrapper draggable by calling .parent().draggable() on your element.
$('#clown').resizable(); //adds a new parent to #clown
$('#clown').parent().draggable(); //makes the new parent draggable
1: The resizable widget creates a wrapper div with css property overflow:hidden
2: The draggable is being moved by changing: top and left property.
3: scenario's:
3.1 When you first initialize the resizable and then draggable, the draggable will get position:relative, relative to the wrapper created by the resizable.(and will get trapped inside the wrapper created by the resizable).
3.2 When you first initialize the draggable and then the resizable, the draggable will get position:static. If you use dev tools in chrome and move the draggable you will see that the top and left properties are changed however the draggable with property position:static will stay inside the wrapper created by the resizable(and visually stay on the same place).
4: this is actually a cool question, because i never really delved into inner workings of the widgets and how they interact with css. Thank you, now i can't sleep until i figured it out :)
I am using jquery-ui draggable. When I drag my box to beyond the bottom of the screen, the body shifts down. How can I prevent this from occurring?
Tried...
I have tried making the draggable to be containment: "*tag*" where tag is html or body.
Still trying containment, I have tried surrounding the layout with a div, however, this breaks the layout scroll-ability of LHS, RHS and center.
The problem is solved by making the body - position: static !important. This then breaks the layout.
For reference, here is the jquery-ui draggable page.
Css Layout
I have a layout which is header, fixed-height-footer, left and right fixed-width-scrollable, fluid center-scrollable. The header and footer is achievable using a large body border hack. See this question for information on the layout. How to have a 3 column layout with fixed left/right, fluid middle and fixed footer?
Reproduction of the problem.
Here is my Fiddle: http://jsfiddle.net/valamas/LrXCA/
Please click and drag the blue box below the footer to see a black band or a further pink band.
Pass scroll: false to your draggable constructor.
By default the auto-scroll option is set to true, if you don't want it, you have to specify scroll: false when creating the draggable. See scroll option on the jQuery draggable page.
Working jsFiddle
I created a couple of nested divs, the inner horizontally resizeable, the outer vertically resizeable. I have it such that resizing a parent div (or the window) causes the children to resize.
However, I'm finding that when a child div is resized, it's ancestors all rx the resize event even even when their sizes don't change.
I'm using Chrome 18.0 on Win7.
Example here: http://jsfiddle.net/m95Ha/
Resize the red & cyan sides and the window, and watch the chars in the black div. For example, resizing the cyan side horizontally causes an 'i' ('#inner' resize event), an 'o' 'i' ('#outer' resize event), and a 'w' (window resize event).
I wouldn't have expected the 'o' or the 'w'.
Is this a jQuery thing, or a Chrome thing, or perhaps the HTML/DOM standard?
This is intended behavior of jQuery UI; the resize method bubbles like normal events. You can filter out resize events that occur on non jQuery UI resizable widgets with the following if necessary:
$('whatever').bind('resize', function(event) {
if (!$(event.target).hasClass('ui-resizable')) {
//do stuff here
}
});
There's some relevant discussion in this question as well - jQuery UI resizable fire window resize event.
Using Jquery UI's tabs I want to be able to set the tab + tab content views together to be a specific height say 500px. Since the height of the tab section varies by theme and I cannot know what height to use in px for the content view so I cannot hard code it. How do you force the whole thing to a specific height?
Thanks!
Put the entire block inside a div and apply max-height CSS property to it.