2013-08-29 29 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

你最終解決您的問題? –

回答

0

最簡單的方法就是使用鏈接like this

它不需要的jQuery或JavaScript,只是增加了使用的ID您的HTML一些元素如href

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