kokimu
5/10/2018 - 6:57 PM

Hack - Fix Double Tap on iOS


<!-- Smooth Scroll & Disabling Double-tap -->
<script type="text/javascript">
  jQuery(document).ready(function($){
     $('a[href*=#]:not([href=#])').on('click touchend', function(e) {
      if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
        var target = $(this.hash);
        target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
        if (target.length) {
          $('html,body').animate({
            scrollTop: target.offset().top
          }, 700);
          return false;
        }
      }
    });
  });
</script>

 <!-- Note: -->
  <!-- 上のコードは、以下の二つのスクリプトを組み合わせたもの、以下の二つは単独だと働くが、両方使うと、Smooth Scroll が働かない。 -->

  <!-- Smooth Scroll Only -->
  <script type="text/javascript">
    jQuery(document).ready(function($){
      $('a[href*=#]:not([href=#])').click(function() {
        if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
          var target = $(this.hash);
          target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
          if (target.length) {
            $('html,body').animate({
              scrollTop: target.offset().top
            }, 700);
            return false;
          }
        }
      });
    });
  </script>

  <!-- Disable Double-tap Issue on iOS Only -->
  <script type="text/javascript">
    $(document).ready(function() {

       $('a').on('click touchend', function(e) {
          var el = $(this);
          var link = el.attr('href');
          window.location = link;
       });

    });
  </script>