View difference between Paste ID: hP6qFa53 and JtZeiTGA
SHOW: | | - or go back to the newest paste.
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)
11+
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
});