Jquery$(window).scrollTop();方法是滚动到页面的特定位置,然后在页面顶部再次滚动

Jquery $(window).scrollTop(); method is scrolling to the particular location of the page and then scorlling again ot the top of the page?

本文关键字:滚动 然后 位置 定位 顶部 方法 scrollTop Jquery window      更新时间:2023-11-16

*我的需求:**

当用户单击特定的HTML锚定标记时,页面就会被卷缩到页面上的特定位置

我的逻辑:

为了对页面的特定位置进行评分,我使用了Jquery$(window).sollTop();方法

我的问题:

当用户单击我网页标题部分的锚定标签(有问题吗?),然后页面滚动到我页面的快速查询部分时。在那之后,它再次烧到了页面的顶部

它想在快速查询部分停下来,不能再拖到页面顶部。

我的代码:

<script type="text/javascript">
     function moveToBottom()
     {
      alert("before scorlling");
      $(window).scrollTop(1042); 
      $('.wpcf7-form-control wpcf7-text wpcf7-validates-as-required').focus();
     alert("after scorlling");
     }
</script>

有人能帮我找到这个页面滚动的解决方案吗?提前谢谢。

尝试使用这个:

  $('html, body').animate({
    scrollTop: $(".customFooterMenu").offset().top
}, 2000);

我想在你的情况下,你想滚动到这个类(customerFooterMenu)

如果上面的方法不起作用,请尝试为要滚动到的div分配一个id,然后使用该id而不是customFooterMenu。

如何使用

$(document).scrollTop(1042);