Browse Source

Get the real Viewport size.

Jay Salvat 11 years ago
parent
commit
79fdefe57b
1 changed files with 20 additions and 3 deletions
  1. 20 3
      src/jquery.vegas.js

+ 20 - 3
src/jquery.vegas.js

@@ -7,7 +7,7 @@
 // http://jaysalvat.com/
 // ----------------------------------------------------------------------------
 
-(function($){
+(function($) {
     var $background = $('<img />').addClass('vegas-background'),
         $overlay = $('<div />').addClass('vegas-overlay'),
         $loading = $('<div />').addClass('vegas-loading'),
@@ -333,8 +333,9 @@
             return;
         }
 
-        var ww = $(window).width(),
-            wh = $(window).height(),
+        var vp = getViewportSize(),
+            ww = vp.width,
+            wh = vp.height,
             iw = $img.width(),
             ih = $img.height(),
             rw = wh / ww,
@@ -402,6 +403,22 @@
         }
     }
 
+    // Get the real viewport size
+    function getViewportSize(){
+        var elmt = window,
+            prop = 'inner';
+
+        if (!('innerWidth' in window)){
+            elmt = document.documentElement || document.body;
+            prop = 'client';
+        }
+
+        return {
+            width:  elmt[prop + 'Width' ],
+            height: elmt[prop + 'Height']
+        };
+    }
+
     // The plugin
     $.vegas = function(method) {
         if (methods[method]) {