Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Sep 16th, 2012  |  syntax: JavaScript  |  size: 1.25 KB  |  views: 32  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. 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.           e.preventDefault();
  12.         if(parseInt(scrollTarget) !== parseInt(jQuery(window).scrollTop())) {
  13.           var intro = jQuery("#intro"),
  14.             nav2 = jQuery(".nav2");
  15.         if (ios) nav2.hide();
  16.           jQuery('html,body').animate({scrollTop:scrollTarget}, 1200, "swing", function(evt) {
  17.           if (ios) {
  18.             nav2.css({position:'absolute', top:scrollTarget + 34});
  19.             var nav2clone = jQuery(".nav2");
  20.             if(intro.height() <= nav2clone.position().top)
  21.               nav2clone.show();
  22.           }
  23.       });
  24.     }
  25.     });
  26.  
  27.     if (ios) {
  28.         jQuery(document).bind('touchmove',function(){
  29.           var intro = jQuery("#intro"),
  30.             nav2 = jQuery(".nav2");
  31.         if(intro.height() <= nav2.position().top)
  32.         {
  33.             nav2.css({position:'fixed', top:'34px'});
  34.             nav2.show();
  35.           }
  36.           else
  37.             nav2.hide();
  38.       });
  39.     }
  40. });
clone this paste RAW Paste Data