即使用户开始滚动页面,我是否可以随时将heading
保持在some other area
文本之上?
如何使用CSS / jQuery进行此操作?
演示: http://jsfiddle.net/h49p65qa/
CSS:
* {
margin: 0;
padding: 0;
}
.site-wrap {
padding:40px 0
}
.some-other-area { }
h1 {
position:fixed;
z-index:1;
top:0;
margin:0;
}
h2 {
padding: 0px;
margin: 0px 0 20px 0;
}
.floatingHeader {
position: fixed;
top: 0;
visibility: hidden;
}
谢谢
答案 0 :(得分:3)
这是你在找什么?
JS:
var el = $(this),
offset = el.offset(),
scrollTop = $(window).scrollTop() + 50,
floatingHeader = $(".floatingHeader", this)

CSS:
.floatingHeader {
position: fixed;
top: 50px;
visibility: hidden;
}

答案 1 :(得分:1)
我是否有可能继续超越其他地区的文字 所有时间 - 即使用户开始滚动页面?
您只需更改top
类的 css属性 .floatingHeader
,以确保它始终低于<h1>Heading</h1>
.floatingHeader {
position: fixed;
top: 25px;
visibility: hidden;
}
这样就可以满足您的两个要求(标题 floatingHeader )。
如果您正在深入讨论,您可以随时更改z-index
demo