所以我得到了jQuery滾動工作在我的頁面上很好。 但我想改變一件事。 我不想在url中顯示錨文本。即。 #products或#contactinfojQuery滾動:防止錨文本出現在url中
HTML代碼:
<div>
<a href="#products">Products</a>
<a href="#contactinfo">Contact info</a>
</div>
<div id="products"></div>
<div id="contactinfo"></div>
jQuery代碼:
$(document).ready(function(){
$('a[href^="#"]').on('click',function (e) {
e.preventDefault();
var target = this.hash,
$target = $(target);
$('html, body').stop().animate({
'scrollTop': $target.offset().top
}, 900, 'swing', function() {
window.location.hash = target;
});
});
});
長鏡頭,但你試過將其更改爲$('一[href^=「#」]')? – LorDex