2014-09-18 5 views
1

동일한 페이지 스크립트의 앵커 링크에 부드러운 스크롤을 삽입하여 웹에 삽입하려하지만 작동하지 않습니다. 나는 그들 중 몇 가지를 시도했지만 아무도 여기에 매끄러운 앵커 스크롤을하기 위해 어떤 스크립트를 사용해야합니까? 내 시도한 사람이 작동하지 않습니다

내가 노력하는 그들 중 일부입니다 ... 작동하지 않습니다 :

Best way to smooth scrolling to an internal link

http://css-tricks.com/snippets/jquery/smooth-scrolling/

Smooth scrolling when clicking an anchor link

http://www.sycha.com/jquery-smooth-scrolling-internal-anchor-links http://www.ezmacwebdesign.com/Demo/smooth-scroll.html

어쩌면 내가하고있다. 뭔가 잘못? 나는

나는 또한 내 헤더 스틱 내 머리 섹션에서이 스크립트를 가지고 ..., 나는이 아주 새로운 오전과 내가 JS와 jQuery를에 대해 거의 아무것도 몰라 <script> </script> 사이에 <head> 부분이 스크립트를 삽입하고 화면을 스크롤하는 동안 문제가 발생했을 가능성이 있습니까?

<script> $(function(){ 
     var stickyHeaderTop = $('#headertop').offset().top; 

     $(window).scroll(function(){ 
       if($(window).scrollTop() > stickyHeaderTop) { 
         $('#headertop').css({position: 'fixed', top: '0px'}); 
         $('#headeralias').css('display', 'block'); 
       } else { 
         $('#headertop').css({position: 'static', top: '0px'}); 
         $('#headeralias').css('display', 'none'); 
       } 
      }); 
     }); 
</script> 

링크 :이 연결되어야

<a href="#vlog"> <div class="hbutton">Vlog</div> </a> 

장소 :

<a name="vlog" id="vlog"><div id="vlog"></div></a> 

도움이 :)

답변

1

당신이로 스크롤에 필요한 스크립트를 포함 했는가에 대한 기대 잘?

그렇지 않으면, JS 다른 코드와 함께 스크립트 태그에이 코드를 추가 시도 :

$(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 
       }, 1000); 
       return false; 
      } 
     } 
    }); 
}); 
+0

내 이크를! 똑똑하고, 매력처럼 일 했어요, 정말 고마워요! – Jockey