我生成img標籤動態再提供阻力,之後,我將其附加到容器中,然後設置其位置在容器中心的大小的功能。這一切工作正常,但追加後,當我撤回頂部和左上方添加img標籤的位置,我越來越頂部0和0。當我調整一次後,我就獲得了正確的位置。爲什麼會發生這種情況,我總是很無情。請幫助。無法獲得頂部和左側值
下面是代碼
var img_clip = document.createElement('img');
$(img_clip).attr("id", "dyndiv" + count);
$(img_clip).attr("src", current_clip) ;
$(img_clip).attr("width", 30);
$(img_clip).attr("height",50);
var $ctrl = $(img_clip).resizable({ containment: '#containment-wrapper'}).parent().addClass("resizable").draggable({ containment: '#containment-wrapper', cursor: 'move',delay: 200,distance: 30, opacity: 0.35});
objid = "dyndiv" + count ;
$(img_clip).css("z-index" , $(img_clip).css("z-index") + count);
$('#sel_obj_text').val("Image");
count++;
$("#containment-wrapper").append($ctrl);
$('#' + objid).parent().position({
of: $("#containment-wrapper"),
my: "center" + " " + "center",
at: "center" + " " + "center"
});
後來在其他部分的代碼,我想從以下行
$(this).parent().css("left")
$(this).parent().css("top")
一個的jsfiddle例子是,在這種情況下非常有幫助! '$(this).parent()'是一個對象嗎?如果是的話,試試'$(this).parent()。offset()。left'(和.top)或者如果你想要相對位置$(this).parent()。position()。left'。 – Armin 2011-12-27 15:02:33
yes $(this).parent()是通過調整大小功能創建的div包裝器。 – 2011-12-27 15:07:16
那麼'.offset()'和/或'.position()'方法應該工作:) – Armin 2011-12-27 15:09:42