jQuery Show/Hide Div when Section is in Viewport

北城以北 提交于 2019-12-08 05:57:18

问题


My code at the moment is here: http://www.jaygeorge.co.uk/gwennan-sage

You'll see two green arrows that are in a fixed position at the bottom of the page. I'm having trouble getting jQuery to hide these divs (#timeline-buttons) when the Timeline section is NOT in view, preferably using the fade() technique.

I've tried a Viewport plugin but can't get it to work properly with if statements, I'm sure it can be done with normal jQuery by measuring div heights somehow.

Any advice appreciated, thanks in advance.


回答1:


Hide the green arrows and then onscrolling, test to see if the timeline div position is greater than the window height plus scrolling offset. If greater then that means that the timeline div is in view and the arrows should be shown.

Here is a quick fiddle demonstrating the effect: http://jsfiddle.net/EADDt/




回答2:


Move these arrows into #gwennan-header and remove the fixed css attribute and set the z-index. That way you won't need any Javascript at all.



来源:https://stackoverflow.com/questions/6031649/jquery-show-hide-div-when-section-is-in-viewport

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!