y 滚动时元素的对齐方式
我想要的是,当有人使用 y 滚动时,即使在这种情况下,标题(包含日期和日期应该可见。)请检查 屏幕截图
使用位置:固定和z-index等的东西
(我见过的例子:--当你打开堆栈溢出并且你的JavaScript被禁用时,那么在这种情况下会出现一条红色消息即使您向下滚动页面,也会出现并继续出现。)
所以我想做的是: -
最初在页面加载时,这一行将位于页面之间(因为上面还有很多其他内容,一旦用户滚动向下它应该对用户可见,即它粘在页面顶部)
What i want to is when somebody use y scroll even in that case the header (which contains days and dates should be visible.) Please check the screen shot
Something using position:fixed and z-index etc.
(example i have seen :-- when u open stack-overflow and ur JavaScript is disabled, then in that case a red colored message will appear and keep appearing even if u scroll down the page.)
So What i want to do is:--
Initially at page load this row will the be in between the page (as there are lot of other things above and once user scroll down it should be visible to user ie this sticks with the top of the page)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解正确的话,您正在寻找一个不在页面顶部但当您向下滚动经过它时粘在顶部的元素?这可以通过 css 和一点 JavaScript 魔法(为了简洁而使用 jQuery)来完成:
如果禁用 JS,您的元素将正常运行。否则,以下代码片段将使其动态化:
现在您只需调整值
100
即可等于页面顶部与元素顶部之间的距离。因此,如果您的元素距顶部250px
,则应使用250
。如果你不确定,你可以尝试一下,直到你得到看起来光滑的东西。If I understand you correctly, you are looking for an element that is not located at the top of the page, but sticks to the top when you scroll down past it? This can be done with css and a little JavaScript magic (jQuery used for brevity):
Your element will behave normally if JS is disabled. Otherwise, the following snippet makes it dynamic:
Now you just have to adjust the value
100
to equal the distance between the top of the page and the top of your element. So, if your element is250px
from the top, you would use250
. If you are not sure you can play around with it until you get something that looks smooth.