이미지를 뷰포트/창 크기에 맞추어야합니다.뷰포트에 이미지 맞추기
나는 그 일을이 코드를 사용
$(".fittedImg").each(function() {
// I want to limit the size, and show a scrollbar on very small viewport
height = ($(window).height() < 725) ? 725 : $(window).height();
width = ($(window).width() < 1150) ? 1150 : $(window).width();
var newWidth, newHeight;
$(this)
.removeAttr("height")
.removeAttr("width"); // reset img size
// calculate dimension and keep it
if (($(this).width()/width) > ($(this).height()/height)) {
newHeight = height;
newWidth = height/($(this).height()/$(this).width());
} else {
newHeight = width/($(this).width()/$(this).height());
newWidth = width;
};
$(this).stop(true, false).animate({
"height": newHeight + "px",
"width": newWidth + "px"
});
});
은 내가 크기 조정에 전화 기능에 해당 코드를 포장, 및 $ ('fittedImg.') 등의 이벤트에 부하()와 $를. ('.fImg'). 준비().
결과가 매우 이상합니다. Chrome에서는 정상적으로 작동하지만 이미지가 반복적으로 새로 고침 될 때마다 늘어납니다. IE에는 꽤 똑같은 문제가 있습니다. Opera는 결코 실패하지 않으며 사파리는 전혀 계산을 무시합니다.
계산 및/또는 이벤트 호출에 문제가 있습니까?
감사합니다.
1. 어떻게해야합니까? load()와 ready()는 충분하지 못하나요? 2. 도움이되지 않습니다. – SRachamim
예제를 상용구로 사용하십시오. '.load()'는 너비/높이를 얻기에 충분해야하지만 핸들러에서 값을 콘솔로 확인할 수 있습니다. – David