ヘルプが必要です。1 ページ レイアウトの Web ページを作成していて、スクリプトへのスクロールがありますが、ナビゲーション バー クラスのボタンを押すと表示されるようにしたいです。私が意味したのは?
ボタンを押すたびにその位置までスクロールしますが、見たい htttp://mysite.com/#top
これは私が持っているものです
$(function(){
$('a[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) {
var targetOffset = $target.offset().top;
$('html,body').animate({scrollTop: targetOffset - 100}, 800); /* Offest 100px because of the fixed nav manu */
return false;
}
}
});
});