2012-03-27 3 views
0

DOM 크기를 창 크기로 설정하는 jQuery 플러그인을 작성했습니다. 창 크기를 조정할 때 따라하고 싶지만 작동하지 않습니다. 코드는 다음과 같습니다.전체 화면 jQuery 플러그인

(function($){ 

    $.fn.fullScreen = function() { 

    return this.each(function() { 
     $(this).css({ 
      "width" : $(window).width(), 
      "height" : $(window).height() 
     }) 
     $(window).resize(function() { 
      $(this).css({ 
       "width" : $(window).width(), 
       "height" : $(window).height() 
      }) 
     }) 
    }); 

    }; 
})(jQuery); 
+0

플러그인이 필요합니까? CSS :'.full-screen {display : block; 높이 : 100 %; 왼쪽 : 0; 위치 : 고정; 상단 : 0; 너비 : 100 %; }'JS :'$ (...). addClass ('전체 화면'); – zzzzBov

답변

1

코드에서 Windows 크기 조정 이벤트의 $ (이)가 창을 참조합니다. 시도해보십시오 :

(function($){ 

    $.fn.fullScreen = function() { 

    return this.each(function() { 
     var self = $(this); 
     $(this).css({ 
      "width" : $(window).width(), 
      "height" : $(window).height() 
     }) 
     $(window).resize(function() { 
      self.css({ 
       "width" : $(window).width(), 
       "height" : $(window).height() 
      }) 
     }) 
    }); 

    }; 
})(jQuery);