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 6746791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:21:52+00:00 2026-05-26T12:21:52+00:00

I’m trying to emulate the behavior of this drag n drop found here How

  • 0

I’m trying to emulate the behavior of this drag n drop found here

How do I change the following code to get the mouse over effect with the rectangle outline? Also is it possible to have it sortable like the example above?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style>
  .demo { width: 320px }

  ul { width: 200px; height: 150px; padding: 2em; margin: 10px; color: black; list-style: none; }
  ul li { border: solid 1px red; cursor: move; }

  #draggable { border: solid 1px #ccc;}
  #droppable { border: solid 1px #ddd; }
</style>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>

<script>
$(document).ready(function() {

var selectedClass = 'ui-state-highlight',
    clickDelay = 600,
    // click time (milliseconds)
    lastClick, diffClick; // timestamps

$("#draggable li")
// Script to deferentiate a click from a mousedown for drag event
.bind('mousedown mouseup', function(e) {
    if (e.type == "mousedown") {
        lastClick = e.timeStamp; // get mousedown time
    } else {
        diffClick = e.timeStamp - lastClick;
        if (diffClick < clickDelay) {
            // add selected class to group draggable objects
            $(this).toggleClass(selectedClass);
        }
    }
})
.draggable({
    revertDuration: 10,
    // grouped items animate separately, so leave this number low
    containment: '.demo',
    start: function(e, ui) {
        ui.helper.addClass(selectedClass);
    },
    stop: function(e, ui) {
        // reset group positions
        $('.' + selectedClass).css({
            top: 0,
            left: 0
        });
    },
    drag: function(e, ui) {
        // set selected group position to main dragged object
        // this works because the position is relative to the starting position
        $('.' + selectedClass).css({
            top: ui.position.top,
            left: ui.position.left
        });
    }
});

$("#droppable, #draggable").droppable({
activeClass: "ui-state-hover",
hoverClass: "ui-state-active",

    drop: function(e, ui) {
        $('.' + selectedClass).appendTo($(this)).add(ui.draggable)
        .removeClass(selectedClass).css({
            top: 0,
            left: 0
        });
    }
});
});
</script>   

</head>
<body>

<div class="demo">
    <p>Available items</p>    
        <ul id="draggable">
        <li>Item 1</li>
    <li>Item 2</li>
    <li>Item 3</li>
    <li>Item 4</li>
</ul>

    <p>Drop Zone</p>
    <ul id="droppable">
    </ul>

</div>

</body>
</html>
  • 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-26T12:21:52+00:00Added an answer on May 26, 2026 at 12:21 pm

    The link you posted has an example created without jQuery, and I have done the same several times myself with a slightly different approach.

    I’m sure there is an easier way in jQuery UI draggable, and the documentation would be the first place to look.

    However, to show how it’s done in regular javacript without a library, wich should probably work with jQuery as well, as it uses regular event listeners, you would do something like this:

    var dropzone;  
        dropzone = document.getElementById("dropzone");  
        dropzone.addEventListener("dragenter", dragin, false);
        dropzone.addEventListener("dragleave", dragout, false);
        dropzone.addEventListener("drop", drop, false);  
    

    This binds the events to functions, that would look something like this:

    function drop(e) {
        //do something when dropped
        e.stopprop, preventdefault etc.
    }
    function dragin(e) {
        //do something when dragged in
        e.stop stuff
    }
    function dragout(e) {
        //do something when dragged out, usually remove the stuff you did above
        e.stop stuff
    }
    

    This is the way it’s normally done, and just as mouseenter and mouseleave, the drag event listeners should work with jQuery, and you could probably use .bind(); to bind them to some sort of action in exactly the same way as the mouse events, allthough I have never tested this as I always do this without jQuery.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text

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.