SHARE
TWEET

Self-adjusting fixed width

ulfben Apr 1st, 2012 137 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*Using JavaScript to keep the "fixed" page width in sync with browser size and orientation changes.
  2. Try rotating your phone or resizing the browser window here; http://www.gotlandindies.org/ */
  3.  
  4. jQuery(document).ready(function() {                                            
  5.         var waiting = false;
  6.         function wait(){
  7.                 if(waiting){
  8.                         clearTimeout(waiting);
  9.                         waiting = false;
  10.                 }
  11.                 waiting = setTimeout(doScale, 100); //a delay to avoid duplicate event calls.  
  12.         }
  13.         function doScale(){
  14.                 var w = jQuery(window).width();
  15.                 //if(w < 1024){ w = 1024; }
  16.                 jQuery('.container').animate({
  17.                                 width:w+'px'
  18.                         }, 800, function(){
  19.                                 jQuery('.container').css('overflow', 'hidden');
  20.                         }
  21.                 );
  22.         }
  23.         jQuery(window).bind('orientationchange', wait);
  24.         jQuery(window).bind('resize', wait);
  25. });
RAW Paste Data
Top