开发者

Jquery drag /drop and clone

开发者 https://www.devze.com 2022-12-17 18:29 出处:网络
Hi I need to achive this .. Ihave a set of droppable items ( basically I am droping designs on a apparel ) and I am dropping a clone..

Hi I need to achive this ..

I have a set of droppable items ( basically I am droping designs on a apparel ) and I am dropping a clone..

If I don't like the dropped object (designs) - I want to delete that by doing something like hidden .

But I am unable to do that.

Please help me..


here is the code

    var clone;
    $(document).ready(function(){
        $(".items").draggable({helper: 'clone',cursor: 'hand'});


     $(".droparea").droppable({
                    accept: ".items",
                    hoverClass: 'dropareahover',
                    tolerance: 'pointer',
                    drop: function(ev, ui)
                    {

              var dropElemId = ui.draggable.attr("id");

              var dropElem = ui.draggable.html();

                      clone = $(dropElem).clone(); // clone it and hold onto the jquery object
                      clone.id="newId";
                      clone.css("position", "absolute");
          clone.css("top", ui.absolutePosition.top);
                      clone.css("left", ui.absolutePosition.left);
              clone.draggable({ conta开发者_JAVA技巧inment: 'parent' ,cursor: 'crosshair'});

                      $(this).append(clone);
                      alert("done dragging ");

                      /lets assume I have a delete button when I click that clone should dissapear so that I can drop another design - but the following code has no effect 
                      //and the item is still visible , how to make it dissapear ?
                      $('#newId').css("visibility","hidden");



               }
        });



    });


Since .clone() returns a jQuery object. clone.id="newId" sets an property on the jQuery object not the DOM element. Since the DOM element doesn't have an id property. $('#newId').length should return null. Test in firebug console

Use:

clone.attr('id', 'newId') 

to set an ID on the cloned object's DOM element.


You can use drop dragabble object function:

drop: function (event, ui) {
                            $(ui.draggable).remove();
                        }

after

$(this).append(clone);

in your script;

0

精彩评论

暂无评论...
验证码 换一张
取 消