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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:54:46+00:00 2026-06-18T04:54:46+00:00

When dropping something in this drop area, the object will be cloned and will

  • 0

When dropping something in this drop area, the object will be cloned and will get part class.

$('.drop').droppable({
    tolerance: 'fit',
    accept: '.drag, .part',
    drop: function (event, ui) {
        var top = ui.position.top;
        var left = ui.position.left;
        var posizione = ui.position;

        if ($(ui.helper).hasClass('drag') ) {
            $(this).append($(ui.helper).clone());
            $('#board .drag').addClass("part");
            $('.part').removeClass("drag");
        };
       ....
)};

There is a way to give doppable/draggable/resizable properties to “part” class without doing this inside drop event, but defining it outside? Because the only way to make it work is to give that inside drop function.

WORK

$('.drop').droppable({
    tolerance: 'fit',
    accept: '.drag, .part',
    drop: function (event, ui) {
        var top = ui.position.top;
        var left = ui.position.left;
        var posizione = ui.position;

        if ($(ui.helper).hasClass('drag') ) {
            $(this).append($(ui.helper).clone());
            $('#board .drag').addClass("part");
            $('.part').removeClass("drag");
        };

        $('.part').resizable({
            containment: "#board",
            aspectRatio: true
        });
        ....
)};

NOT WORK

$('.drop').droppable({
    tolerance: 'fit',
    accept: '.drag, .part',
    drop: function (event, ui) {
        var top = ui.position.top;
        var left = ui.position.left;
        var posizione = ui.position;

        if ($(ui.helper).hasClass('drag') ) {
            $(this).append($(ui.helper).clone());
            $('#board .drag').addClass("part");
            $('.part').removeClass("drag");
        };

        ....
)};
$('.part').resizable({
            containment: "#workarea",
            aspectRatio: true
});

I’m new to javascript and jquery, so if you find other errors, please report.
Thanks for helping.

EDIT: complete code http://jsfiddle.net/funnydj/qtBfJ/2/

  • 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-06-18T04:54:47+00:00Added an answer on June 18, 2026 at 4:54 am

    By addressing the jQuery collection $('.part') inside the drop handler, you will affect all elements in the document with class="part".

    Typically, it is necessary only to address the element that’s just been dropped/cloned, and given that that element is given class="part", I’m guessing that only it needs to be addressed. All previously dropped/cloned elements should already have received the appropriate treatment.

    If I’m right, then you probably want something like this :

    $('.drop').droppable({
        tolerance: 'fit',
        accept: '.drag, .part',
        drop: function (event, ui) {
            var top = ui.position.top;
            var left = ui.position.left;
            var posizione = ui.position;
    
            if(ui.helper.hasClass('drag') ) {
                var $part = ui.helper.clone().removeClass("drag ui-draggable-dragging").addClass("part");
                $part.appendTo($(this));
                $part.resizable({
                    containment: "#board",
                    aspectRatio: true
                });
                $part.draggable({
                    tolerance: 'fit',
                    revert: 'invalid', //resterà non valido finchè non droppo in un punto valido
                    containment: "#workarea",
                    stop: function () {
                        var top2 = ui.position.top;
                        var left2 = ui.position.left;
                        $("#workarea").append('<div>spostata</div>');
                        $(this).draggable('option', 'revert', 'invalid'); //quando lo lascio torna indietro perche' il revert è invalid'
                    }
                });
                $part.droppable({
                    greedy: true,
                    //tolerance: 'intersect',
                    drop: function (event, ui) {
                        if (!$(ui.helper).hasClass('part')) {
                            ui.draggable.draggable('option', 'revert', true);
                        }
                    }
                });
            };
            inserite++;
            $("#workarea").append('<div>' + top + '-' + left + '--' + inserite + '</div>');
        }
    });
    

    You could tidy things significantly by defining the option-maps in an outer scope, but they must be applied inside.

    I would probably do something like this :

    var inserite = 0;
    
    part_options = {
        resizable: function(ui) {
            return {
                ...
            }
        },
        draggable: function(ui) {
            return {
                ...
            }
        },
        droppable: function(ui) {
            return {
                ...
            }
        }
    };
    
    
    $('.drop').droppable({
        tolerance: 'fit',
        accept: '.drag, .part',
        drop: function (event, ui) {
            var top = ui.position.top;
            var left = ui.position.left;
            var posizione = ui.position;
    
            if(ui.helper.hasClass('drag') ) {
                var $part = ui.helper.clone().removeClass("drag ui-draggable-dragging").addClass("part");
                $part.appendTo($(this));
                $part.resizable(part_options.resizable.call(this, ui));
                $part.draggable(part_options.draggable.call(this, ui));
                $part.droppable(part_options.droppable.call(this, ui));
                //or one long chained command if you prefer.
            };
            inserite++;
            $("#workarea").append('<div>' + top + '-' + left + '--' + inserite + '</div>');
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this enormous database : # # Dropping tables # DROP TABLE IF
I have a droppable with a drop event handler: $(this).droppable({ drop:function(){ console.log('OMG You Dropped
I'm reading a spreadsheet and and dropping it into an array (I will shortly
Drag is not working after dropping on the area. I have used Jquery UI
This question could easily take multiple paths, so I will hit the more specific
I do something like svn diff > /mystuff/current.diff. I want to view this .diff
I'm trying to implement Future.get(long, TimeUnit) in terms of TimeUnit.timedWait(Object, long) . It's not
I'm dropping an object ( ScatterViewItem ) on a SurfaceListBox with the s:SurfaceDragDrop event,
I'm new to this and I'm trying to get my head around the implementation
I have a Component like this: public partial class FontScalingManager : Component { ...other

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.