Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Sep 16th, 2012  |  syntax: JavaScript  |  size: 1.28 KB  |  views: 49  |  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 Document
  2. jQuery(document).ready(function() {
  3.  
  4.   var device = navigator.userAgent.toLowerCase();
  5.   var ios = device.match(/(iphone|ipod|ipad)/);
  6.  
  7.  //function that returns element's y position
  8.    
  9.     jQuery("a[href*=#]").on('click', function(e) {
  10.       var scrollTarget = jQuery(this.hash).offset().top;
  11.       if(scrollTarget)
  12.           e.preventDefault();
  13.         if(parseInt(scrollTarget) !== parseInt(jQuery(window).scrollTop())) {
  14.           var intro = jQuery("#intro"),
  15.             nav2 = jQuery(".nav2");
  16.         if (ios) nav2.hide();
  17.           jQuery('html,body').animate({scrollTop:scrollTarget}, 1200, "swing", function(evt) {
  18.           if (ios) {
  19.             nav2.css({position:'absolute', top:scrollTarget + 34});
  20.             var nav2clone = jQuery(".nav2");
  21.             if(intro.height() <= nav2clone.position().top)
  22.               nav2clone.show();
  23.           }
  24.       });
  25.     }
  26.     });
  27.  
  28.     if (ios) {
  29.         jQuery(document).bind('touchmove',function(){
  30.           var intro = jQuery("#intro"),
  31.             nav2 = jQuery(".nav2");
  32.         if(intro.height() <= nav2.position().top)
  33.         {
  34.             nav2.css({position:'fixed', top:'34px'});
  35.             nav2.show();
  36.           }
  37.           else
  38.             nav2.hide();
  39.       });
  40.     }
  41. });