<div id="brandNameAnchor"></div> //站位层 初始高度0
<div id="brandName"></div> //menu
$(document).ready(function() {
var $window = $(window);
var brandName = $('#brandName')
var brandNameAnchor = $('#brandNameAnchor');
$window.scroll(function() {
var window_top = $window.scrollTop();
var div_top = brandNameAnchor.offset().top;
if (window_top > div_top) {
brandName.addClass('stick');
brandNameAnchor.height(brandName.height()); //menu悬浮后 站位层高度等于menu层高度顶替原位置
} else {
brandName.removeClass('stick');
brandNameAnchor.height(0);
}
});
});
网友评论