Prevent DIV elements from overlapping in CSS and jQuery when dragging under certain conditions

How can I prevent divs from overlapping? Below are my CSS, script, and HTML:

///css
#body {
    background-image: url('images/marginup.jpg');
    height: 734px;
    width: 640px;
}

#body2 {
    background-image: url('images/margindown.jpg');
    height: 100px;
    width: 640px;
}
#drag1 {
    width: 636px;
    height: 107px;
    background-image: url('images/caliperupleft.png');
    background-repeat: no-repeat;
}
#drag2 {
    width: 636px;
    height: 107px;
    background-image: url('images/caliperdownleft.png');
    background-repeat: no-repeat;
}
#drag4 {
    margin-left: 430px;
    margin-top: 102px
}
#drag5 {
    margin-left: 432px;
    margin-top: -50px
}

//// my script

$(document).ready(function() {
        $("#drag3").hide();
        $(".draggable").draggable({
            containment : "parent"

        });


        $(document).mousemove(function(e){
      $('#status').html(e.pageX +', '+ e.pageY);
   }); 

    });


/// my html body

                       .<div id="drag1" class="draggable" >
                <img id="drag4" src="images\caliperupright.png"></img>
            </div>

            <div id="drag2" class="draggable">

                <img id="drag5" src="images\caliperdownright.png"></img>
            </div>

I need help ensuring that the contents of the two divs in the body can be dragged without overlapping. I attempted to create a function for ondrag that would stop dragging when overlap occurs, but it didn't work as expected. Any suggestions?

Answer №1

Looking for solutions? You may find what you need here.

The draggable elements offer customizable features.

Best of luck in your endeavors!

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

Stop the execution of the setTimeout function when the webpage loads in JavaScript

In my postgres database, I have a table named students for storing student information. The structure of the table is as follows: id first_name last_name time_remind 1 pers1 pers1_name 2022-07-30 21:30 2 pers2 pers2_name 2022-07-30 20:38 Current ...

Reorganizing JSON data using JavaScript

I've been diving into learning JavaScript and I've hit a roadblock at work with structuring JSON data. Despite spending a considerable amount of time on it, I just can't seem to crack the correct format for this JSON challenge. Here's w ...

Arranging progress bars between various nodes using HTML and CSS

I am currently facing a challenge in creating a stepping wizard form layout that features a bar at the top of the page. This bar displays a dynamic number of steps (nodes) and progress bars that connect these nodes. However, I am encountering difficulties ...

Is there a way to extract all the content from a webpage's body using BeautifulSoup?

Looking to extract text from a medical document webpage for a Natural Language Processing project using BeautifulSoup, but encountering challenges. The specific website in question is located here: The goal is to capture the entire text body by utilizing ...

Tips for Positioning Sidebar Elements Relative to Content IDs

My goal is to have sidebar elements align with specific id tags in the main content, rather than just stacking up one after another. I want the sidebar elements to align with certain id tags mentioned in the main post content. The image at shows the basic ...

React Native formInput Component with Underline Decoration

Utilizing the FormInput element in React Native Elements, I have observed a line underneath each FormInput component. Interestingly, one line appears fainter than the other. https://i.sstatic.net/ZD8CI.png This is how the form looks: <View style={sty ...

The confirm() function shows up before the background on a blank layout

I'm facing an issue where whenever my confirm() function pops up, the alert box displays correctly but then the background turns blank. I've tried various solutions like moving the entire if statement to the bottom of the page or at the end of th ...

PHP bug causing inaccuracies in output results

I've written a PHP script to determine a student's final grade, taking into account weight and target grades. However, the output value it generates is incorrect. Below is my current PHP code: <?php $numassignments = isset($_GET['numass ...

Dealing with Unwanted Navbar Opacity in Bootstrap 4

Currently working on a React.js project using Bootstrap 4. The issue I'm facing involves two elements - navbar and alert, both implemented from Bootstrap4. Strangely, when setting position:fixed for both elements (overriding CSS), they become semi-tra ...

Utilizing VueJS to choose an item from a list and exhibit it using a function

My goal is to retrieve the element I click on, displayed in a list, and then print this element using a method within my Vue instance through the mail-list tag in index.html. I have a Vue component that iterates over a JSON object and only displays two at ...

Ways to generate multiple choices for options

Is there a method to provide multiple options within an option? I am utilizing CSelect to create options. One of the options needs to include additional options. <CSelect custom name="select_pattern_filter" id="select_pattern_filter" ...

Generating a dataframe with cells that have a combination of regular and italicized text using the sjPlot package functions

I've been trying to set up a basic data table where the genus name in the "Coral_taxon" column is italicized, but the "spp." part following it remains lowercase. I thought of using the expression() function for each row in "Coral_taxon," but so far, I ...

Changing the URL dynamically based on user interaction with jQueryLet's leverage the power of

In continuation to my previous post, I am looking to dynamically change a URL based on the selected language. For example, if the current URL is href="../folder/Languages/English/test/test.html, clicking or selecting another language should update it to: h ...

The IE condition is failing to work properly with .js and .css files

I've been trying to use this code to load the ie.css file specifically for IE browsers, but for some reason it's not working. I'm feeling a bit confused here - can anyone help me figure this out? <html> <head> <titl ...

Leveraging Repeater in ASP.NET along with jQuery for handling DataTables

I am a beginner with ASP.NET technology and I am exploring the use of datatable jQuery with a repeater. However, I am facing an issue where the datatable is not displaying the values inside the table, it only shows the headings (as shown below). These val ...

Is there a way to extract the text that is displayed when I hover over a specific element?

When I hover over a product on the e-commerce webpage (), the color name is displayed. I was able to determine the new line in the HTML code that appears when hovering, but I'm unsure how to extract the text ('NAVY'). <div class="ui ...

Angular2 material dropdown menu

Currently, I am studying angular2 with its material design. One of the modules I am using is md-select for material and here is a snippet of my code: <md-select> <md-option value="1">1</md-option> <md-option value="2">2< ...

Finding the identifier for resources through excluding external influences

I am currently facing an issue with the full calendar plugin. In my set up, I have 3 resources along with some external events. The problem arises when I try to drop an external event onto the calendar - I want to retrieve the resource id from which the ev ...

Ajax is coming back with a value that is not defined

Currently, I am working on a search function that is responsible for searching a name from the database. When the user clicks "add", the selected item should appear below the search field so that it can be saved in the database. However, I am encountering ...

Tips for implementing a document ready function on a nested page within a larger full-page website

I am currently working on a website that utilizes fullpage.js, but the same principle applies to all single-page websites. I am trying to figure out how to implement the $(document).ready() function on a 'nested' page within the site. Since every ...