페이지가 새로 고쳐지면 어떤 이유로이 작업이 올바르게 실행되지 않습니다. 그렇지 않으면 잘 작동합니다. id.background는 body 태그에 있습니다.jquery background resize
var theWindow = $(window),
$bg = $("#background"),
aspectRatio = $bg.width()/$bg.height();
function resizeBg() {
if ((theWindow.width()/theWindow.height()) < aspectRatio) {
$bg.removeClass()
.addClass('bgheight');
} else {
$bg.removeClass()
.addClass('bgwidth');
}
}
theWindow.resize(function() {
resizeBg();
}).trigger("resize");
문서 준비 이벤트에서 크기 조정을 트리거하고 있습니까? 예 :'$ (document) .ready (function() {theWindow.trigger ('resize');}); ' –
그래, prob가 추가 했어야했다. –