我目前在这里使用它来跳转到页面上的 id 标记,尽管如果可能的话我还需要能够跳转到 X 方向,这会很棒吗?
所以基本上我只想要一个按钮,该按钮将滚动到放置在页面 x 方向上的 div ,与垂直方向相同:)
//anchors
function filterPath(string) {
return string
.replace(/^\//,'')
.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
.replace(/\/$/,'');
}
$('a[href*=#]').each(function() {
if ( filterPath(location.pathname) == filterPath(this.pathname)
&& location.hostname == this.hostname
&& this.hash.replace(/#/,'') ) {
var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) +']');
var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
if ($target) {
var targetOffset = $target.offset().top + 90;
$(this).click(function() {
$('html, body').animate({scrollTop: targetOffset}, 600);
return false;
});
}
}
});