gpt4 book ai didi

jquery - 使用 jQuery 在用户滚动过去时更改 div css

转载 作者:搜寻专家 更新时间:2023-10-31 22:03:09 24 4
gpt4 key购买 nike

当用户滚动经过一个 div 时,我需要将其 css 更改为 position:fixed。很像这里所做的:http://imakewebthings.com/jquery-waypoints/shortcuts/sticky-elements/但只有普通的 jquery,没有插件。
一旦用户滚动到另一个 div,div 也必须停止滚动。
例如:

<div id="stuff"></div>
<div id="this"></div>//must start scrolling with user when user reaches it.
<div id="footer"></div>// when #this reaches within say, 10px, of #footer it must stop in it's current position, in order to prevent overlap

我假设我会使用 .scroll().css(),但我不知道从那里去哪里。

最佳答案

我注意到在你的回答中 #this 一旦你进入 #footer 就会突然消失。我已经调整了您的答案,以允许 #this 坚持 #footer 并滚动更流畅。

我的演示使用了略有不同的标记并且更加冗长,所以跳转到 jsFiddle 并检查它。

演示: jsfiddle.net/Marcel/e9hyw/

关于jquery - 使用 jQuery 在用户滚动过去时更改 div css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16128979/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com