2012-09-14 2 views
3

매끄러운 두루마리가 스크롤되지 않는 Safari (Mac OS 만 해당, Windows는 정상적으로 작동 함)에서 이상한 문제가 있습니다. 단지 링크로 이동하지만 다른 모든 브라우저에서 작동합니다 (Windows Safari에서도 가능).Safari (Mac OS)에서 jQuery 부드러운 스크롤 문제

내 jQuery를이

  <script type="text/javascript"> 
     (function($){ 
    $.extend({ 
     smoothAnchors : function(speed, easing, redirect){ 
      speed = speed || "slow"; 
      easing = easing || null; 
      redirect = (redirect === true || redirect == null) ? true : false; 
      $("a").each(function(i){    
       var url = $(this).attr("href"); 
       if(url){ 
        if(url.indexOf("#") != -1 && url.indexOf("#") == 0){ 
         var aParts = url.split("#",2); 
         var anchor = $("a[name='"+aParts[1]+"']"); 
         if(anchor){               
          $(this).click(function(){      
           if($(document).height()-anchor.offset().top >= $(window).height() 
           || anchor.offset().top > $(window).height() 
           || $(document).width()-anchor.offset().left >= $(window).width() 
           || anchor.offset().left > $(window).width()){     
            $('html, body').animate({ 
             scrollTop: anchor.offset().top, 
             scrollLeft: anchor.offset().left 
            }, speed, easing, function(){ 
             if(redirect){ 
              window.location = url 
             } 
            }); 
           } 
           return false;       
          }); 
         } 
        } 
       } 
      }); 
     } 
    }); 
})(jQuery); 
</script> 

이고 사람이 문제가 알려 주시기 바랍니다 알고 있다면 내 HTML이

<nav id="nav"> 
<ul id="navigation"> 
    <li><a href="#About" class="fade"> ABOUT</a></li> 
<a name="About"></a> 

처럼 보인다!

매우 감사드립니다.

답변

2

저에게 좋습니다!

(function($) { 
    $.fn.SmoothAnchors = function() { 

     function scrollBodyTo(destination, hash) { 

      // Change the hash first, then do the scrolling. This retains the standard functionality of the back/forward buttons. 
      var scrollmem = $(document).scrollTop(); 
      window.location.hash = hash; 
      $(document).scrollTop(scrollmem); 
      $("html,body").animate({ 
       scrollTop: destination 
      }, 200); 

     } 

     if (typeof $().on == "function") { 
      $(document).on('click', 'a[href^="#"]', function() { 

       var href = $(this).attr("href"); 

       if ($(href).length == 0) { 

        var nameSelector = "[name=" + href.replace("#", "") + "]"; 

        if (href == "#") { 
         scrollBodyTo(0, href); 
        } 
        else if ($(nameSelector).length != 0) { 
         scrollBodyTo($(nameSelector).offset().top, href); 
        } 
        else { 
         // fine, we'll just follow the original link. gosh. 
         window.location = href; 
        } 
       } 
       else { 
        scrollBodyTo($(href).offset().top, href); 
       } 
       return false; 
      }); 
     } 
     else { 
      $('a[href^="#"]').click(function() { 
       var href = $(this).attr("href"); 

       if ($(href).length == 0) { 

        var nameSelector = "[name=" + href.replace("#", "") + "]"; 

        if (href == "#") { 
         scrollBodyTo(0, href); 
        } 
        else if ($(nameSelector).length != 0) { 
         scrollBodyTo($(nameSelector).offset().top, href); 
        } 
        else { 
         // fine, we'll just follow the original link. gosh. 
         window.location = href; 
        } 
       } 
       else { 
        scrollBodyTo($(href).offset().top, href); 
       } 
       return false; 
      }); 
     } 
    }; 
})(jQuery); 

$(document).ready(function() { 
    $().SmoothAnchors(); 
}); 

https://github.com/alextrob/SmoothAnchors

+0

감사합니다! 이것은 나를 위해 잘 작동하는 것 같다. 딸꾹질이 뭔지 모르겠지만 100 % 효과가 있습니다! 고맙습니다. – Ben

+0

그것은 Safary, lorry-lags에 늦는다. –

+0

@Ultra 나는 이것이 Alex가 아니라 나에게 문제라고 생각한다. ;-) – yckart