2013-08-29 2 views
0

나는이 새로운 페이지를 열리고 ID로 스크롤이 스크립트일부 내부 링크 애니메이션 작업을 얻기

var jump = function (e) { 
if (e) { 
    e.preventDefault(); 
    var target = $(this).attr("href"); 
} else { 
    var target = location.hash; 
} 

$('html,body').animate(
{ 
    scrollTop: $(target).offset().top 
}, 2000, function() { 
    location.hash = target; 
}); 

} 

$('html, body').hide(); 

$(document).ready(function() { 
    $('a[href^=#]').bind("click", jump); 

    if (location.hash) { 
    setTimeout(function() { 
    $('html, body').scrollTop(0).show(); 
    jump(); 
    }, 0); 
} else { 
    $('html, body').show(); 
} 
}); 

나는 그것이 내부 링크와 현재 페이지의 스크롤 애니메이션입니다해야합니까 싶어 무엇 . 어떻게 그것을 통합합니까?

+0

당신이 당신의 문제를 해결 결국처럼 ID를 사용하여 HTML에 추가 ? –

답변

0

가장 쉬운 방법은 링크 (like this)를 사용하는 것입니다.

그것은 jQuery를 또는 자바 스크립트를 필요로하지 않는다

, 그냥 몇 가지 요소가 href

<a id='exampleTop' href='#exampleMiddle'>I'm an example! Click to go down</a>