我在容器 div 中动态添加 img 标签。在创建 img 时,我添加了 2 个可拖动和调整大小的类,然后附加到容器中。所以我可以拖动但无法调整大小。可能是什么问题?
下面是创建img标签的代码
var img = document.createElement('img');
$(img).attr("id", "dyndiv" + count);
$(img).attr("width", 40);
$(img).attr("height", 100);
$(img).attr("src", 'Uploads/' + window.frames['ifrm'].document.getElementById('dvFileName').innerHTML);
var $ctrl = $(img).addClass("draggable resizable ui-widget-content")
.draggable({
containment: '#containment-wrapper',
cursor: 'move',
snap: '#containment-wrapper'
})
.resizable({
aspectRatio:true,
containment: '#containment-wrapper'
});
objid = "dyndiv" + count;
count++;
$(img).css("margin-top", Math.ceil(140/2) + 'px');
$(img).css("margin-left", Math.ceil(60/2) + 'px');
$(img).css({
'top':20,
'left':30,
'zindex':400 + count
});
$("#containment-wrapper").append($ctrl);
这是@Andrew Whitaker 建议的更改代码,但它仍然无法正常工作,请帮我解决这个问题..
var $wrap_div = $("<div></div>", { 'id' : "dyndiv_img" + count }) ;
$wrap_div.addClass("wrapper");
$wrap_div.resizable({ containment: '#containment-wrapper'});
var img_clip = document.createElement('img');
$(img_clip).attr("id", "dyndiv" + count);
$(img_clip).attr("src", current_clip ) ;
var $ctrl = $(img_clip).addClass("draggable ui-resizable ui-widget-content").draggable({ containment: '#containment-wrapper', cursor: 'move',delay: 200,distance: 30, opacity: 0.35}).wrap($wrap_div);
objid = "dyndiv" + count ;
count++;
$(img_clip).css({'top':20,'left':30});
//($ctrl).resizable({ containment: '#containment-wrapper'}) ;
$("#containment-wrapper").append($ctrl);
$('#' + objid).position({
of: $( "#containment-wrapper" ),
my: "center" + " " + "center",
at: "center" + " " + "center"
});