1
我有一個滾動條的表。我如何讓滾動條自動滾動到表格中的項目。 。我如何讓滾動條自動滾動到表中的項目
我有一個滾動條的表。我如何讓滾動條自動滾動到表格中的項目。 。我如何讓滾動條自動滾動到表中的項目
optikalefxx幫我解決了這個問題。 http://www.youtube.com/watch?v=S6pzabpUmoc
HTML
<p class="navigation">
<h2><a href="#link1">Link 1</a> | <a href="#link2">Link 2</a> | <a href="#link3">Link 3</a> | <a href="#link4">Link 4</a></h2>
</p>
的Javascript
$(function() {
// catch all clicks on a tags
$("a").click(function() {
// check if has hash
if(this.hash) {
// get rid of the # sign
var hash = this.hash.substr(1);
// get the position of the <a name>
var $toElement = $("a[name="+hash+"]");
var toPosition = $toElement.position().top;
// scroll/animate to that element
$("body,html").animate({
scrollTop : toPosition
},1500,"easeOutExpo");
// don't do the jump
return false;
}
});
if(location.hash) {
var hash = location.hash;
window.scroll(0,0);
$("a[href="+hash+"]").click();
}
});
希望它可以幫助你。
是否允許使用jQuery? – pimvdb 2011-03-19 11:19:55
是不是有一個scrollTo mehod使用?我不在我的正常位置,所以我不能挖掘正確的參考。 – some 2011-03-19 11:35:31