Jquery-ui draggable and dynamic Jquery-ui draggable?

后端 未结 4 1824
一个人的身影
一个人的身影 2020-12-20 15:55

This is my code taken from http://jqueryui.com/demos/draggable/



 
           


        
4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-20 16:35

    I'm actually going to say for performance reasons, to instead use:

    $('.draggable:not(.ui-draggable)').draggable();
    

    This will prevent attempting to re-initialize already draggable elements using jQuery UI's built in class. Also, if your code down the road modifies the properties of an individual draggable that may not match the properties of a new draggable, you could end up with some being reset.

    Nothing wrong with being specific with jQuery.

    UPDATE

    Didn't specify for which instance to use this. Based on Ricardo's Edit:

    $(function() {
        $( ".draggable" ).draggable();
        $('.content').click(function(){
            var htmlData='

    Drag me around

    '; $('.demo').append(htmlData); $('.draggable:not(.ui-draggable)').draggable(); //Here }); });

    I'm also now seeing you were manually adding the ui-draggable class. You don't need to do that. In fact, it makes what I said not work.

提交回复
热议问题