如果一个元素链接到同一页上的锚定,那么jQuery smooth scroll可以工作,但是当链接到另一页上的锚定时,它不会平滑滚动。
我的jQuery脚本有什么明显的问题吗?
<script>
jQuery(function($) {
// //////////////////////// Smooth Scroll To Specific Element On Page ////////////////////////
$(document).ready(function() {
$('a[href^="#"]').not('.carousel-control-prev').not('.carousel-control-next').bind('click.smoothscroll', function(e) {
e.preventDefault();
var hash = this.hash;
jQuery('html, body').animate({
scrollTop: jQuery(hash).offset().top - 65
}, 1500, function(){});
});
});
//////////////////////// Smooth Scroll To Specific Element On Different Page ////////////////////////
$(document).ready(function(){
var urlHash = window.location.href.split("#")[1] || false;
if (urlHash.length > 0)
$('html,body').animate({
scrollTop: $('#' + urlHash).offset().top - 60
}, 2500);
});
});
</script>