单击按钮显示向下滚动时应固定的div。 Div没有正常显示?

时间:2021-06-26 21:26:08

I have a fixed header which has a button (menu icon) on it. Whenever I scroll down the header will show (as it’s fixed). When I click on the menu button the menu is then also in a fixed position on the right hand side. When I scroll down both header and menu show which is fine. THE PROBLEM is when I initially scroll down half way down the page AND THEN click on the menu button the menu (div) is at the top-when I scroll a bit then it displays. There's a delay in this. Do you know how I can get the menu to display regardless of where I am on the page (in terms of y position)????

我有一个固定的标题,上面有一个按钮(菜单图标)。每当我向下滚动标题时都会显示(因为它已修复)。当我点击菜单按钮时,菜单也位于右侧的固定位置。当我向下滚动标题和菜单显示哪个很好。问题是,当我最初向下向下滚动页面的一半时,然后单击菜单按钮,菜单(div)位于顶部 - 当我滚动一点然后显示。这有延迟。你知道我怎么能得到菜单显示无论我在页面上的位置(在y位置)????

Top is set as 100px for the menu in a class (as the headers height is 100px-so i want the menu to show under it) BUT obviously if I’m already half way down the page the menu still takes into account the top: 100px however, I want it to change because I’ve scrolled down so the top position value would be different.

对于类中的菜单,Top设置为100px(因为标题高度为100px-所以我希望菜单显示在它下面)但很明显,如果我已经在页面的一半,菜单仍然考虑到顶部:然而,100px,我希望它改变因为我向下滚动所以顶部位置值会有所不同。

Any help??

1 个解决方案

#1


0  

Taking a shot in the dark, I think your problem is where your fixed position checks are taking place - I.E, I'm guessing they're within the .scroll event of the window.

在黑暗中拍摄,我认为你的问题是你的固定位置检查发生的地方--I,我猜它们在窗口的.scroll事件中。

Before you scroll down, and you click on the menu button, it is set to display block in its initial position - which is correct, because you haven't scrolled down yet.

在向下滚动之前,单击菜单按钮,它将设置为在其初始位置显示块 - 这是正确的,因为您还没有向下滚动。

However, if you scroll down first, then display the menu - it's still going to display in it's initial position - because the check is in your .scroll event - which you haven't fired while the menu has been open.

但是,如果先向下滚动,然后显示菜单 - 它仍将显示在其初始位置 - 因为检查位于.scroll事件中 - 您在菜单打开时未触发该事件。

Try applying the position check in the button logic too.

尝试在按钮逻辑中应用位置检查。

#1


0  

Taking a shot in the dark, I think your problem is where your fixed position checks are taking place - I.E, I'm guessing they're within the .scroll event of the window.

在黑暗中拍摄,我认为你的问题是你的固定位置检查发生的地方--I,我猜它们在窗口的.scroll事件中。

Before you scroll down, and you click on the menu button, it is set to display block in its initial position - which is correct, because you haven't scrolled down yet.

在向下滚动之前,单击菜单按钮,它将设置为在其初始位置显示块 - 这是正确的,因为您还没有向下滚动。

However, if you scroll down first, then display the menu - it's still going to display in it's initial position - because the check is in your .scroll event - which you haven't fired while the menu has been open.

但是,如果先向下滚动,然后显示菜单 - 它仍将显示在其初始位置 - 因为检查位于.scroll事件中 - 您在菜单打开时未触发该事件。

Try applying the position check in the button logic too.

尝试在按钮逻辑中应用位置检查。