Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 15th, 2012  |  syntax: None  |  size: 1.57 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Javascript and Performance
  2. $(function(){
  3.  
  4.  
  5.     var $window = $(window);
  6.     var windowHeight = $window.height();
  7.     var windowWidth = $window.width();
  8.     var content = $("#content");
  9.     var section = content.children("section");
  10.     var sectionsNumbers = section.length-1;
  11.     var illusion =  $(".illusion1");
  12.     var mask = $('#mask');
  13.     // Scroll sets
  14.  
  15.     var windowScrollX = ((sectionsNumbers+1)*windowWidth)-windowWidth;
  16.     var windowScrollY = ((sectionsNumbers+1)*windowHeight)-windowHeight;
  17.  
  18.     content.css({"width":windowScrollX+windowWidth,"height":windowScrollY+windowHeight});
  19.  
  20.     illusion .css({"width":windowScrollX+windowWidth,"height":windowScrollY+windowHeight});
  21.  
  22.  
  23.     // Set mask w and h
  24.  
  25.     mask.css({"width":windowWidth,"height":windowHeight});
  26.     $(".scrollRule").css("height", (sectionsNumbers+1)*windowHeight);
  27.  
  28.  
  29.     section.each(function(sectionCount,val) {
  30.  
  31.         // Defines its width and height
  32.         var $this = $(this);
  33.         $this.css({"width":windowWidth,"height":windowHeight,"left":sectionCount*windowWidth,"top":sectionCount*windowHeight});
  34.  
  35.  
  36.     });
  37.  
  38.     // When window scrolls
  39.  
  40.  
  41.     var angleVar = windowScrollX/windowScrollY;
  42.     var curScrollTop;
  43.     $(window).scroll(function(){
  44.         var $this = $(this);
  45.         curScrollTop = $this.scrollTop();
  46.         content.stop().animate({left: "-"+curScrollTop*angleVar, top: "-"+curScrollTop}, {duration: 1250, easing: 'easeOutQuart'});
  47.        illusion.stop().animate({left: "-"+curScrollTop*angleVar*0.5, top: "-"+curScrollTop*0.5}, {duration: 1250, easing: 'easeOutQuart'});        
  48.     });
  49.  
  50. });