我有两个div,一个固定在顶部,我想在第二个div接触时显示固定div的边框颜色.我想要像雅虎那样. 这里是 … div class="container"div class="header"/divdiv class="content"/div/div.containter{ width:700px; margi
这里是 …
<div class="container">
<div class="header"></div>
<div class="content"></div>
</div>
.containter{
width:700px;
margin:0 auto;
}
.header{
height:50px;
width:100%;
position:fixed;
top:0;
left:0;
background:yellow;
}
.content{
min-height:500px
width:100%;
background:red;
}
用css或jquery做的任何方法?
您可以使用jQuery来获得此效果:假设这是你的类,当窗口滚动时显示阴影.
.shadow{
box-shadow: 0px 3px 5px #888888;
}
然后在窗口的scrolltop大于0时添加一个jQuery.
$(function(){
var $window = $(window),
$header = $('.header'),
$this = $(this); // <-----here you can cache your selectors
$window.on('scroll', function(){
if($this.scrollTop() > 0){
$header.addClass('shadow');
}else{
$header.removeClass('shadow');
}
}).scroll();
});
Demo Fiddle here
Demo with cached vars
