由于某种原因,我无法顺利向下滚动到锚点。谁能明白为什么?
这是html:
<div id="onward">
<a href="#xdroneslogan" class="btn">
<i class="icon-chevron-down icon-white"></i> Onward
</a>
</div>
这是javascript:
<script>
$("#onward a").click(function(){
var onwardId = $(this).attr("href");
$("html, body").animate({scrollTop: $(onwardId).offset().top}, "slow");
return false;
});
</script>
答案 0 :(得分:4)
<强> JS: - 强>
$("#onward a").click(function () {
var onwardId = $(this).attr("href");
$("html, body").animate({
scrollTop: $(onwardId).offset().top
}, "slow");
return false;
});
<强> HTML: - 强>
<div id="xdroneslogan" style="height:1000px;background:red;"></div>
<div id="onward">
<a href="#xdroneslogan" class="btn"><i class="icon-chevron-down icon-white"></i> Onward</a>
</div>
还要确保jQuery.fx.off
设置为false。