Adjustable Size with jQuery UI - Resizing Multiple Divs Causes Movement of Adjacent Divs

I've been experimenting with a webpage that consists of a div element containing multiple nested divs and jQuery UI resizable functionality. Essentially, it's a dashboard comprised of individual widgets. My goal is to resize each widget independently without affecting the positioning of other widgets inside the parent div.

Currently, resizing one div causes displacement of other adjacent divs. I want to be able to resize a single div without influencing others (even if the resized div overlaps or goes behind other divs). Despite trying various approaches, I'm encountering challenges in implementing this.

I've set up a jsFiddle (http://jsfiddle.net/gattml/Th75t/) to showcase my current progress.

Below are some code snippets:

<div class="carousel-inner">
    <div class="item">

    <div class="widgetList">
        <div class="widgetRefresh">
            <div class="widgetResizable">
                <div class="widget-header">
                    <span>header1</span>
                </div>
                <div class="widget-body">
                    <span>body1</span>
                </div>
            </div>
        </div>
    </div>

    ...other "widget" divs here...

    </div>
</div>

.carousel-inner {
    position: relative;
    width: 100%;
    overflow: hidden;
    outline: 1px solid red;
}

.item {
    left: 0;
    display: block;
    position: relative;
    outline: 1px solid blue;
}

.widgetList {
    background-color: #f5f5f5;
    display: inline-block;
    margin: 1em;
    position: relative;
    vertical-align: top;
    min-width: 80px;
    outline: 1px solid green;
}

.widgetResizable {
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    min-width: 80px;
    overflow: hidden;
    outline: 1px dashed red;
}

.widget-header {
    outline: 1px dashed blue;
}

.widget-body {
    overflow: hidden;
    width: auto;
    height: 100px;
    padding: 4px;
    outline: 1px dashed green;
}

var $widget = $(".widgetList");
var $widgetResizable = $widget.find(".widgetResizable");
$widgetResizable.css("height", "170px");
$widget.draggable({
    cursor: "move",
    grid: [4, 4],
    handle: ".widget-header",
    opacity: 0.85,
    zIndex: 100
});
$widgetResizable.resizable({
    grid: [4, 4],
    handles: "e, s, se",
    minHeight: 100,
    minWidth: 80
});

How can I achieve resizable "widget" divs that maintain their positions without affecting other "widget" divs?

Appreciate any help!

Answer №1

For optimal results, ensure that your moving box is positioned absolutely. You have the option to either assign a class within the start:function(){} or incorporate CSS properties accordingly. Additionally, don't forget to set a z-index value to ensure your box appears on top of other elements.

Check out this JSFiddle for reference

start:function(event,ui){
        ui.element.css('position','absolute');
    }

Alternatively, you can improve the code by:

start:function(event,ui){
        ui.element.addClass('active');
    }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Understanding the significance of 'href = '<? = variable ?>' on an HTML/PHP webpage

I must admit, I have a slight inkling that I'll feel a tad foolish once it's clarified, but could someone kindly explain what the following statement accomplishes? href='<?= $authUrl ?>' This line is extracted from the Google AP ...

Is it possible to use Highcharts in AngularJs without jQuery?

Is there a way to use Highcharts without relying on the full jQuery library? The current popular option seems to require jQuery, but I'm having trouble getting it to work without it: https://github.com/pablojim/highcharts-ng Can I develop a Highchart ...

Achieving cross-browser compatibility with JSONP and supporting IE9 syntax in jQuery, as well as ensuring functionality

I am encountering an issue with a specific part of my code that needs to be utilized when an IE browser is detected, but removed when any other browser is in use: $.ajax({ url: 'http://mapit.mysociety.org/areas/'+ulo, ...

Adjust the appearance attribute of FormField within the designated theme

Currently, I am collaborating within an NX Monorepo and utilizing a shared ui-components library that extends the capabilities of Angular Material Components. Despite using different themes for various applications, I am aiming to incorporate appearance=&a ...

The table is not properly displaying within the parent scrolled div due to issues with the fixed positioning

Apologies for any language barrier. I am encountering an issue with a PHP page that includes a table meant to be displayed as position:fixed; however, it consistently appears above the scrollbars and does not stay within the parent div. View screenshot he ...

designing the border at the bottom of the existing menu selection

I am trying to enhance the look of my current-menu-item div by adding a border at the bottom. It seems simple enough to achieve this by simply including the border in the div. However, I'm facing an issue with the width and position of the border. Ide ...

Having difficulty duplicating a button with a click event using jQuery

I have implemented a button that reveals a phone number when clicked using the code below: var shortNumber = $("#phone_ch").text().substring(0, $("#phone_ch").text().length - 12); var onClickInfo = "_gaq.push(['_trackEvent', 'EVENT-CATEGOR ...

Sequential Loop Complexity in jQuery Deferred

Despite searching through numerous answers on stackoverflow, I haven't found a solution that fits my complex problem. What I need to accomplish is: Run a for loop with a variable length that fetches table rows using an ajax query. Once all the rows ...

Is there a way to reference a background-image using "<img src>" syntax?

Why won't the background image display? It only displays as an img src. How can I call the background-image correctly? <body> <div id="page" style="background- image:url(https://storage.blob.core.windows.net/name/image.png)"> ...

Guide on inserting text input value into the href attribute of a hyperlink

Lately, I've been facing an issue that has been troubling me for the past few hours. I have a search input field where users can enter text and click send. The entered text should then be added to the href attribute and sent to the results page for qu ...

What is the best way to prioritize items on a list in JavaScript?

Looking to organize your to-do list items by priority? In this task list, users can enter an item, select a priority level, and add it to the list. Here is an example HTML form: <input id="task" type="text"/> <select id="priority"> <o ...

Styling will_paginate Links in Rails 3 - A Guide

When it comes to coding layout, how should the link be styled? <a href="#" class="class1 class2 class3"><span>Previous</span></a> <a href="#" class="class1 class2 class3"><span>Next</span> In my search for a solu ...

Issue with Setting Value in JQuery Select Box

I am in the process of designing a webpage that allows users to edit listings they have created on my website. These listings fall under three main categories, each with its own set of subcategories. To streamline this process, I am implementing AJAX to dy ...

Utilizing a jQuery autocomplete feature to access an object

In the JSON data I am using, there are two main sections for GOD and LEG, each containing information about different ships. I want to extract all the ship names from both GOD and LEG categories and utilize them in a JQuery autocomplete feature. { "GOD" ...

Is one round the limit for my JavaScript image slider?

After studying the JavaScript Chapter on W3Schools, I attempted to create an image slider. Initially, everything worked perfectly for the first cycle. For instance, when I clicked the next button, the slides continued to slide until the end of the slidesho ...

Dynamic image swapping using JSON key in Angular

Trying to display different icons based on a property that contains specific words. If the property includes "Health Care" or "Health Care .....", I want to show one image, otherwise another. I've tried using ng-show but my syntax seems off. Any sugge ...

What is the best way to automatically show scrollbars when a page loads using JavaScript?

How can I make the vertical scrollbar appear as soon as the page loads using javascript? I am currently using a jquery slide toggle animation that causes the vertical scrollbar to show up because it makes the page longer. However, when the scrollbar appear ...

Achieve automated zooming out using highcharts-ng through code

Currently, I am using Highcharts-ng as seen on https://github.com/pablojim/highcharts-ng Upon inspecting the source code, I have noticed some interesting functionalities in the directive utilizing scope.$on which I can leverage for broadcasting. One examp ...

Can we dynamically add an identical DOM structure by clicking a button using jQuery?

I currently have ten text fields within a single div. I am interested in including another set of ten text fields with the same name, class, and id. Is there a way to recycle the existing DOM structure mentioned above, or will I need to generate and add t ...

Utilize JQuery to modify hover state when focused and restrict tab navigation to specific areas on the keyboard

I'm currently working with a JQgrid in one of my projects (Check out the JFiddle here). and I have some specific requirements: 1.) I want the save & cancel button to become highlighted when a user tabs to it, similar to how it behaves on mouse ov ...