我的 jQuery 遇到了一些问题,我正在寻找一些解决方案来为我现有的 slideDown
添加一些东西。功能。
我觉得很有趣的是 2010 年的这个问题/答案 http://stackoverflow.com/questions/4034659/is-it-possible-to-animate-scrollop-with-jquery
这个问题的不同之处在于我正在寻找 scrollTop
的解决方案每次都不同<a> anchor
.
在我下面的示例中,<a href"#">
假设移动到顶部。
这可能吗?
HTML
<div class="next_btn" id="next_btn_show_step_3">
<a href="#"><?php echo $lang ['next']; ?></a>
</div>
<article class="order_form_step_3" id="banner_step_3">
</article>
jQuery
$(document).ready(function(){
$("#banner_step_3").hide();
$("#next_btn_show_step_3").click(function(e){
$("#banner_step_3").slideDown(500);
e.preventDefault();
});
});
最佳答案
您可以像这样轻松调整该答案:
$("html, body").animate({ scrollTop: Math.floor($('#yourElement').offset().top) + "px" });
关于javascript - 我可以在不编写函数的情况下使用 scrollTop 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20623564/