2012-04-12 87 views
1

我使用jquery-imagetool插件來裁剪圖像。我的jQuery代碼看起來像:從功能參數jquery當前元素

$('div.image img').imagetool({ 
    viewportWidth: 171, 
    viewportHeight: 267 
}) 

我想從div.image元素的CSS得到viewportWidth參數,所以我需要將當前元素(IMG)和調用父()得到它。

任何人都可以幫助我嗎?

回答

5

使用每個單獨處理圖像,然後您可以獲得div的寬度。

$('div.image img').each(function() { 
    var width = $(this).closest('div.image').width(); 
    $(this).imagetool({ 
     viewportWidth: width, 
     viewportHeight: 267 
    }); 
}); 
+0

感謝您的快速回復,它的作品完美 – 2012-04-12 12:12:15

+0

@sharipov_ru np,隨時將其標記爲已接受。 – 2012-04-12 12:57:32