页面滚动时,使Div浮动

$(window).scroll(function (e) {
var $el = $('.divHeaderFloat');
var isPositionFixed = ($el.css('position') == 'fixed');
if ($(this).scrollTop() > 10 && !isPositionFixed) {
$el.css({ 'position': 'fixed', 'top': '0px' });
}
if ($(this).scrollTop() == 0 && isPositionFixed) {
$el.css({ 'position': 'relative', 'top': '0px' });
}
});
下面按本人需求设置的Div样式

background-color: #ffffff;
width: 100%;
border-bottom: 1px solid #BBBDBF;
box-shadow: 0 0 5px #888;
z-index: 100;
position: relative;
height: 50px;

 

posted @ 2020-07-08 16:48  叶叶叶失秋  阅读(251)  评论(0编辑  收藏  举报