简体   繁体   English

ScrollTop函数的问题-过度滚动

[英]Issue with ScrollTop function - Over scrolling

I am experiencing an issue with my WordPress site - it uses a ScrollTop function to scroll to each section break. 我的WordPress网站遇到问题-它使用ScrollTop函数滚动到每个分节符。 What I am experiencing is that when scrolling, it doesn't scroll to the right location. 我遇到的是,滚动时不会滚动到正确的位置。

I've look all over the code, and can't determine what is causing the issue. 我遍历了所有代码,无法确定是什么导致了问题。 You can see the basic code below for ScrollTop, nothing too different. 您可以在下面看到ScrollTop的基本代码,没什么不同。

 var hash = this.hash;

   // animate
   jQuery('html, body').stop().animate({
       scrollTop: jQuery(this.hash).offset().top,

     }, 1000, 'swing', function(){

       // when done, add hash to url
       // (default click behaviour)
       window.location.hash = hash;
     });

I've attempted offsetting the scroll, but each section seems to have different overscroll. 我试图抵消滚动,但每个部分似乎都有不同的过度滚动。

I've removed all CSS padding and margins which hasn't changed the issue. 我删除了所有CSS填充和边距,但都没有改变问题。 Has anyone experienced a similar issue with scrolling before? 有人曾经遇到过类似的滚动问题吗?

The strange aspect is, that if you click the same link again, it figures it out and scrolls to the right section ID. 奇怪的是,如果您再次单击相同的链接,它将找出该链接并滚动到右侧的部分ID。

You can find a link to my website here . 您可以在此处找到指向我的网站的链接。

I've currently got an issue with FadeIn which I'm working on, so ignore that part of it. 我目前正在处理FadeIn的一个问题,因此请忽略该部分。

Would it be a good assumption that the scroll and fadeIn are conflicting each other? 一个很好的假设是,scroll和fadeIn相互冲突吗? The FadeIn on some sections does in fact increase the length of the Div. 实际上,某些部分的FadeIn确实会增加Div的长度。

Yes, fadeIn is probably the reason since it changes heights of the elements. 是的,fadeIn可能是原因,因为它会更改元素的高度。 You could avoid this by applying fadeIn animations for the divs that are above the selected section before you manipulate the scrollTop. 您可以通过在操作scrollTop之前对选定部分上方的div应用fadeIn动画来避免这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM