Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果您访问《经济学人》网站上的一篇文章。例如:
http://www.economist.com/node/17629757
当您向下滚动页面超过某个点时(使用 PAGEDOWN 按钮或使用 DOWNARROW 键递增滚动),会出现一个红色的粘性标题。
那是 jQuery 吗?
这是如何实施的?
《经济学人》使用Apture服务,该服务包括粘性标题和页面上的一些其他功能。(标头的 ID 为“aptureD”,所以我开始使用 Google 搜索。)如果您想要的只是那个确切的标头,您可以使用他们的服务。
通过 JavaScript 添加的内容只是position : fixed。
您可以使用 Apture 或制作自定义置顶标题。看例子。
有两种方法可以实现:position:fixed和position:absolute。第一个非常基础,您将无法获得任何滑动动画。第二个是您的示例中使用的。这是一个很好的教程,带有演示和源代码。
position:fixed
position:absolute