如果你知道如何使用的开发工具,那么你可以在里面http://riotindustries.com/
看到header
股利分配的fixedtop
类一旦用户从上向下滚动的350px
。
你可以做到这一点使用jQuery
,我已经迅速创建了一个示例jsFiddle为您检查,虽然你将需要进一步修改样式,根据您的需求,因为它很简单。在我的jsFiddle中发生的事情是,当您滚过250px
时,header
被分配了fixedtop
类。
HTML:
<header>This is a nice header, bro!</header>
<div id="longcontent"></div>
CSS:
header {
position: fixed;
background: gray;
color: black;
width: 500px;
text-align: center;
padding: 50px;
left: 50%;
transform: translate(-50%, 0);
top: 30px;
}
.fixedtop {
width: 100%;
background: black;
color: white;
padding: 50px 0px;
text-align: center;
box-shadow: 1px 1px 1px red;
top: 0px;
}
#longcontent {
height: 1000px;
}
的jQuery:
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if (scroll >= 250) {
$("header").addClass("fixedtop");
} else {
$("header").removeClass("fixedtop");
}
});
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if (scroll >= 250) {
$("header").addClass("fixedtop");
} else {
$("header").removeClass("fixedtop");
}
});
header {
position: fixed;
background: gray;
color: black;
width: 500px;
text-align: center;
padding: 50px;
left: 50%;
transform: translate(-50%, 0);
top: 30px;
}
.fixedtop {
width: 100%;
background: black;
color: white;
padding: 50px 0px;
text-align: center;
box-shadow: 1px 1px 1px red;
top: 0px;
}
#longcontent {
height: 1000px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header>This is a nice header, bro!</header>
<div id="longcontent"></div>
谢谢你downvote ...我希望你会需要一个像我一些关键词..我真的想看看你会做什么在这种情况下.. – m1clee 2014-10-18 23:07:21
使用滚动事件更改类 – charlietfl 2014-10-18 23:14:03
事件?像
...? – m1clee 2014-10-18 23:16:02