2011-12-06 4 views
2

페이지가 새로 고쳐지면 어떤 이유로이 작업이 올바르게 실행되지 않습니다. 그렇지 않으면 잘 작동합니다. 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"); 
+0

문서 준비 이벤트에서 크기 조정을 트리거하고 있습니까? 예 :'$ (document) .ready (function() {theWindow.trigger ('resize');}); ' –

+0

그래, prob가 추가 했어야했다. –

답변

1

이 플러그인을 살펴보고 싶습니다. 몇 번 사용했습니다.

http://bavotasan.com/2011/full-sizebackground-image-jquery-plugin/

은 당신이 $('document').ready(function(){}); 내부에 쓴 코드가 있습니까?

+0

예, prob가 추가해야합니다. 나는 링크를 확인해 볼께. 고마워. –

+0

'window'도 시도해보십시오. – sirmdawg

+0

@mkprogramming - OP가 $ (window)를 theWindow에 지정하고 있습니다. '$ (window) .ready()'가 도움이된다고 생각한다면, 윈도우는 onload 이벤트를 던집니다. –