Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2.             (function() {
  3.  
  4.                 // detect if IE : from http://stackoverflow.com/a/16657946     
  5.                 var ie = (function(){
  6.                     var undef,rv = -1; // Return value assumes failure.
  7.                     var ua = window.navigator.userAgent;
  8.                     var msie = ua.indexOf('MSIE ');
  9.                     var trident = ua.indexOf('Trident/');
  10.  
  11.                     if (msie > 0) {
  12.                         // IE 10 or older => return version number
  13.                         rv = parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
  14.                     } else if (trident > 0) {
  15.                         // IE 11 (or newer) => return version number
  16.                         var rvNum = ua.indexOf('rv:');
  17.                         rv = parseInt(ua.substring(rvNum + 3, ua.indexOf('.', rvNum)), 10);
  18.                     }
  19.  
  20.                     return ((rv > -1) ? rv : undef);
  21.                 }());
  22.  
  23.  
  24.                 // disable/enable scroll (mousewheel and keys) from http://stackoverflow.com/a/4770179                 
  25.                 // left: 37, up: 38, right: 39, down: 40,
  26.                 // spacebar: 32, pageup: 33, pagedown: 34, end: 35, home: 36
  27.                 var keys = [32, 37, 38, 39, 40], wheelIter = 0;
  28.  
  29.                 function preventDefault(e) {
  30.                     e = e || window.event;
  31.                     if (e.preventDefault)
  32.                     e.preventDefault();
  33.                     e.returnValue = false;  
  34.                 }
  35.  
  36.                 function keydown(e) {
  37.                     for (var i = keys.length; i--;) {
  38.                         if (e.keyCode === keys[i]) {
  39.                             preventDefault(e);
  40.                             return;
  41.                         }
  42.                     }
  43.                 }
  44.  
  45.                 function touchmove(e) {
  46.                     preventDefault(e);
  47.                 }
  48.  
  49.                 function wheel(e) {
  50.                     // for IE
  51.                     //if( ie ) {
  52.                         //preventDefault(e);
  53.                     //}
  54.                 }
  55.  
  56.                 function disable_scroll() {
  57.                     window.onmousewheel = document.onmousewheel = wheel;
  58.                     document.onkeydown = keydown;
  59.                     document.body.ontouchmove = touchmove;
  60.                 }
  61.  
  62.                 function enable_scroll() {
  63.                     window.onmousewheel = document.onmousewheel = document.onkeydown = document.body.ontouchmove = null;  
  64.                 }
  65.  
  66.                 var docElem = window.document.documentElement,
  67.                     scrollVal,
  68.                     isRevealed,
  69.                     noscroll,
  70.                     isAnimating,
  71.                     container = document.getElementById( 'container' ),
  72.                     trigger = container.querySelector( 'button.trigger' );
  73.  
  74.                 function scrollY() {
  75.                     return window.pageYOffset || docElem.scrollTop;
  76.                 }
  77.                
  78.                 function scrollPage() {
  79.                     scrollVal = scrollY();
  80.                    
  81.                     if( noscroll && !ie ) {
  82.                         if( scrollVal < 0 ) return false;
  83.                         // keep it that way
  84.                         window.scrollTo( 0, 0 );
  85.                     }
  86.  
  87.                     if( classie.has( container, 'notrans' ) ) {
  88.                         classie.remove( container, 'notrans' );
  89.                         return false;
  90.                     }
  91.  
  92.                     if( isAnimating ) {
  93.                         return false;
  94.                     }
  95.                    
  96.                     if( scrollVal <= 0 && isRevealed ) {
  97.                         toggle(0);
  98.                     }
  99.                     else if( scrollVal > 0 && !isRevealed ){
  100.                         toggle(1);
  101.                     }
  102.                 }
  103.  
  104.                 function toggle( reveal ) {
  105.                     isAnimating = true;
  106.                    
  107.                     if( reveal ) {
  108.                         classie.add( container, 'modify' );
  109.                     }
  110.                     else {
  111.                         noscroll = true;
  112.                         disable_scroll();
  113.                         classie.remove( container, 'modify' );
  114.                     }
  115.  
  116.                     // simulating the end of the transition:
  117.                     setTimeout( function() {
  118.                         isRevealed = !isRevealed;
  119.                         isAnimating = false;
  120.                         if( reveal ) {
  121.                             noscroll = false;
  122.                             enable_scroll();
  123.                         }
  124.                     }, 600 );
  125.                 }
  126.  
  127.                 // refreshing the page...
  128.                 var pageScroll = scrollY();
  129.                 noscroll = pageScroll === 0;
  130.                
  131.                 disable_scroll();
  132.                
  133.                 if( pageScroll ) {
  134.                     isRevealed = true;
  135.                     classie.add( container, 'notrans' );
  136.                     classie.add( container, 'modify' );
  137.                 }
  138.                
  139.                 window.addEventListener( 'scroll', scrollPage );
  140.                 trigger.addEventListener( 'click', function() { toggle( 'reveal' ); } );
  141.             })();
  142.         </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement