2011-02-10 38 views
1

enter image description here幫助與容器調整圖像

好了,所以我只是想適當調整DIV,並具有圖像裏面調整爲好。

下面是動態生成的所述容器和圖像的一個例子:

<div id="imgD' + i + '" style="border:1px solid red;display:inline-block;position:absolute;"> 
    <img alt="Big" id="imgA' + i + '" width="' + Math.round(resourceData[i][2] * currentScale) + '" height="' + Math.round(resourceData[i][3] * currentScale) + '" src="' + uploadFolder + '/' + imgData[resourceData[i][1]][1] + '" /> 
</div> 

然後,圖像已Jquery的可調整大小添加到其上,並且該容器具有可拖動添加到其上。所有工作正常。直到我嘗試在客戶端放大時調整這兩個元素的大小。

這裏是我的調整大小代碼:

 $('#imgD' + i).css("width", (resourceData[i][2]*currentScale)); 
     $('#imgD' + i).css("height", (resourceData[i][3]*currentScale)); 

     // Lets try every combination, like a hero! 
     $('#imgA' + i).css("width", (resourceData[i][2]*currentScale)); 
     $('#imgA' + i).css("height", (resourceData[i][3]*currentScale)); 
     $('#imgA' + i).attr("width", (resourceData[i][2]*currentScale)); 
     $('#imgA' + i).attr("height", (resourceData[i][3]*currentScale)); 

     $('#imgD' + i).css("left",(resourceData[i][4]*currentScale) + "px"); 
     $('#imgD' + i).css("top", (resourceData[i][5]*currentScale) + "px"); 

圖像的縮放圖標事情右下角會顯示這是一個問題與jQuery的調整大小?

回答

2

我沒有,我害怕知道答案,但你可以通過鏈接一個元素的方法優化代碼相當多,像這樣:

 $('#imgD' + i).css({ width: (resourceData[i][2]*currentScale), 
          height: (resourceData[i][3]*currentScale)}); 
// Lets try every combination, like a hero! 
    $('#imgA' + i).css({ width: (resourceData[i][2]*currentScale), 
          height: (resourceData[i][3]*currentScale)}) 
        .attr({ width: (resourceData[i][2]*currentScale), 
          height: (resourceData[i][3]*currentScale)}); 
    $('#imgD' + i).css({ left: (resourceData[i][4]*currentScale) + "px", 
          top: (resourceData[i][5]*currentScale) + "px"}); 
+0

我相信你知道這一點,但其他人看着這個帖子可能不會。 – Neil 2011-02-10 16:40:45

0

jQuery的resiable增加了一個DIV來圖片。

('#imgA' + i).parent().css("width", (resourceData[i][2]*currentScale)); 
$('#imgA' + i).parent().css("height", (resourceData[i][3]*currentScale)); 
$('#imgA' + i).css("width", (resourceData[i][2]*currentScale)); 
$('#imgA' + i).css("height", (resourceData[i][3]*currentScale)); 

使用父選擇器調整該div的大小。