我有一個圖片網站,並已實現無限滾動的圖片。 問題是,我不知道如何在加載後使用jQuery調整圖像大小。如何設置使用ajax加載的圖像的寬度?
我使用jQuery 1.5版本的drupal。
這是到目前爲止我的代碼不工作:
jQuery(body).delegate("#region-content","onchange",function() {
jQuery('#region-content img').each(function() {
var desiredWidth = 520; // Max width for the image
var ratio = 0; // Used for aspect ratio
var width = jQuery(this).width(); // Current image width
var height = jQuery(this).height(); // Current image height
if(width != desiredWidth){
ratio = desiredWidth/width; // get ratio for scaling image
jQuery(this).css("width", desiredWidth); // Set new width
jQuery(this).css("height", height * ratio); // Scale height based on ratio
height = height * ratio; // Reset height to match scaled image
width = width * ratio; // Reset width to match scaled image
}
});
});
確保圖像實際上是加載這樣的jQuery可以通過看到的寬度和高度'。就緒()'。 – Broxzier