2014-11-21 5 views
0

여기 내 코드입니다. 이견있는 사람?수 없습니다()

+0

centerAlign을 image.load의 안에 넣으십시오. –

+0

괜찮아 보입니다. http://jsfiddle.net/isherwood/8qmrft67 – isherwood

+0

@ black123 내부에서 함수를 호출 하시겠습니까? : S – stu177

답변

1

해결책을 찾았습니다. 크기를 조정할 때로드가 호출되었습니다. 이미로드 된 것으로 추측하면 크기 조정시 실행되지 않습니다. 변경된 :

function centerAlign(image, parent) { 
    var imageWidth = image.width(); 
    var parentWidth = parent.width(); 
    if(imageWidth != 0) { 
     var trim = (parentWidth - imageWidth)/2; 
     image.css("marginLeft", trim); 
    } 
} 

$(window).resize(function() { 
    centerAlign($(".swiper-slide img"), $(".swiper-slide")); 
}); 

$(document).ready(function() { 
    $(".swiper-slide img").load(function() { 
     centerAlign($(".swiper-slide img"), $(".swiper-slide")); 
    }); 
}); 

이제는 ready() 내에서만 load를 호출하고 resize() 내에서는 호출하지 않습니다. 희망이 다른 사람을 돕는다.

+0

하루를 기다려야 만 할 수 있습니다. – stu177