好吧,基本上我有:
<button class="contactButton">XYZ</button>
当用户按下此按钮时,我希望我的页面向下滚动到特定的 div。
我尝试过这个:
$(".contactButton").click(function () {
$("html,body").animate({
scrollTop: $(".specificDivClass").offset().top
}, 1100);
});
我还尝试了该网站的其他解决方案,但没有结果。我是 jQuery 新手,感谢您的建议。
最佳答案
这里有一个解决方案 https://jsfiddle.net/psfLbo1n/
$(".contactButton").click(function () {
$("html,body").animate({
scrollTop: $(".specificDivClass").offset().top
}, 1100);
});
.div1{
height: 700px;
width: 100%;
background: red;
}
.specificDivClass{
height: 1000px;
width: 100%;
background: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="contactButton">XYZ</button>
<div class="div1">
</div>
<div class="specificDivClass">
</div>
关于jquery - 如何在 jQuery 中正确滚动顶部到 div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45332858/