1
我正在使用函数来平滑滚动页面的子部分。防止指定锚上的默认值
代码所指
event.preventDefault();
-to防止页面跳转到被点击锚当顶部,但它也没有包括hashtag追加到所使用的搜索引擎优化的URL。
这是我正在使用的滚动功能。
<script type="text/javascript">
$('.secondaryNav a').click(function(event){
event.preventDefault();
//calculate destination place
var dest=0;
scrolling = false;
if($(this.hash).offset().top > $(document).height()-$(window).height()){
dest=$(document).height()-$(window).height();
}else{
dest=$(this.hash).offset().top;
}
//go to destination
$('html,body').animate({scrollTop:dest}, 2000,'easeInOutCubic',function() {
});
});
</script>
感谢您的解释。这将很好地工作。 – hyperdrive
不客气:-) –