Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6967743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:21:40+00:00 2026-05-27T16:21:40+00:00

When I drag an element over another div on which I have a mouseover

  • 0

When I drag an element over another div on which I have a mouseover event, the event doesn’t trigger. However, it works if I hover over it without dragging.

Is there a way to detect hover events on an element if I drag another one over it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:21:40+00:00Added an answer on May 27, 2026 at 4:21 pm

    Here is an example using the X-Y coordinate solution.

    Working example on jsfiddle

    The example can be improved, but is a good starting point.

    Simply keeps track of the mouse location and checks if it appears to be inside any bounding boxes of the droppable objects. Hence, if the mouseup event fires on any one of them, dragged object is dropped.

    You can also use the coordinates of the object you are dragging for detecting if its on a droppable box, but it requires a little more code for finding the bounding box coords and using the mouse is enough for me.

    The code uses jQuery but no jQueryUI.
    I tested in Chrome, Firefox and Opera, but not IE 🙂

    I’m also adding the code to here if jsfiddle is not accessible.

    HTML

    <p>Drag orange boxes to grey ones</p>
    <div class="droppable"></div>
    <div class="droppable"></div>
    <div class="droppable"></div>
    <div class="droppable"></div>
    
    <div class="draggable"></div>
    <div class="draggable"></div>
    <div class="draggable"></div>
    

    CSS

    .droppable {
        width:50px;
        height:50px;
        float: left;
        background-color: #DDD;
        margin: 5px;
    }
    
    .draggable {
        width:40px;
        height:40px;
        float: right;
        background-color: #FC0;
        margin: 5px;
        cursor: pointer;
    }
    
    .dropped {
        background-color: #FC0;
    }
    
    .somethingover {
        background-color: #FCD;
    }
    

    JS

    var dragged, mousex, mousey, coordinates = [];
    
    var continueDragging = function(e) {
        // Change the location of the draggable object
        dragged.css({
            "left": e.pageX - (dragged.width() / 2),
            "top": e.pageY - (dragged.height() / 2)
        });
    
        // Check if we hit any boxes
        for (var i in coordinates) {
            if (mousex >= coordinates[i].left && mousex <= coordinates[i].right) {
                if (mousey >= coordinates[i].top && mousey <= coordinates[i].bottom) {
                    // Yes, the mouse is on a droppable area
                    // Lets change the background color
                    coordinates[i].dom.addClass("somethingover");
                }
            } else {
                // Nope, we did not hit any objects yet
                coordinates[i].dom.removeClass("somethingover");
            }
        }
    
        // Keep the last positions of the mouse coord.s
        mousex = e.pageX;
        mousey = e.pageY;
    }
    
    var endDragging = function(e) {
        // Remove document event listeners
        $(document).unbind("mousemove", continueDragging);
        $(document).unbind("mouseup", endDragging);
    
        // Check if we hit any boxes
        for (var i in coordinates) {
            if (mousex >= coordinates[i].left && mousex <= coordinates[i].right) {
                if (mousey >= coordinates[i].top && mousey <= coordinates[i].bottom) {
                    // Yes, the mouse is on a droppable area
                    droptarget = coordinates[i].dom;
                    droptarget.removeClass("somethingover").addClass("dropped");
                    dragged.hide("fast", function() {
                        $(this).remove();
                    });
                }
            }
        }
    
        // Reset variables
        mousex = 0;
        mousey = 0;
        dragged = null;
        coordinates = [];
    }
    
    var startDragging = function(e) {
        // Find coordinates of the droppable bounding boxes
        $(".droppable").each(function() {
            var lefttop = $(this).offset();
            // and save them in a container for later access
            coordinates.push({
                dom: $(this),
                left: lefttop.left,
                top: lefttop.top,
                right: lefttop.left + $(this).width(),
                bottom: lefttop.top + $(this).height()
            });
        });
    
        // When the mouse down event is received
        if (e.type == "mousedown") {
            dragged = $(this);
            // Change the position of the draggable
            dragged.css({
                "left": e.pageX - (dragged.width() / 2),
                "top": e.pageY - (dragged.height() / 2),
                "position": "absolute"
            });
            // Bind the events for dragging and stopping
            $(document).bind("mousemove", continueDragging);
            $(document).bind("mouseup", endDragging);
        }
    }
    
    // Start the dragging
    $(".draggable").bind("mousedown", startDragging);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a container element that you can drag objects around in. I want
Is it possible to have a WPF window/element detect the drag'n'dropping of a file
I have some UI functionality for drag and drop, but when an element is
I have Drag/Drop functionality in my page embedded using YAHOO.js which is initalized at
I have a WPF 4 app which I want to enable drag and drop
I have two li elements which are jQuery draggable. When I drag and drop
I have a problem with jQuery Drag&Drop. I have a draggable element and lots
I have some very simple jquery as listed below: $(.block).hover(function(){ $(.drag).stop().fadeIn(1000); }, function(){ $(.drag).stop().fadeOut(1000);
I have an openlayers map and I have positioned a div to sit inside/over
I have a drag UI program, where the mouse cursor on the draggable element

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.