简体   繁体   中英

how to make new live / cloned element resizable with jquery ui?

i am creating html elements live and appending them to the window.

The issue im having is that i can't use jquery ui on them. I have tried the deffer method, but that doesn't work as well.

What i am trying to accomplish is to clone the last div , add it to the container and make it resizable

here's some code jsfiddle :

<div id="container" class="ui-widget-content">
     <h3 class="ui-widget-header">Containment</h3>

    <div id="" class="ui-state-active resizable">
         <h3 class="ui-widget-header">Resizable</h3>

    </div>
    <div id="" class="ui-state-active resizable">
         <h3 class="ui-widget-header">Resizable</h3>

    </div>
</div>
<button class="add">add</button>

#container {width: 600px;height: 300px;}
#container h3 {text-align: center;margin: 0;margin-bottom: 10px;}
.resizable {width: 100px;height: 100px;float: left;}
.resizable, #container {padding: 0.5em;}

var dfd = $.Deferred();
dfd.done(function () {
    var lastDiv = $('.resizable').last();
    var lastDivClone = lastDiv.clone();
    lastDivClone.appendTo('#container');
    return lastDivClone;
});

$('.add').on("click", function () {
    var x = dfd.resolve();
    x.resizable("enable");
});

$(".resizable").resizable({
    containment: "#container",
    grid: 50
});

any ideas?

Remove the resizable handle first.

lastDivClone.appendTo('#container').find('.ui-resizable-handle').remove()
    .end().resizable({
        containment: "#container",
        grid: 50
    });

http://jsfiddle.net/ExplosionPIlls/945p6/2/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM