刚刚在另一个网站上做了类似的事情.
基本上,我从“固定”位置过渡到“相对”位置,但可以适应您的使用:
var header = $('#header');
var ad = $('#ad');
var min_scroll = 25; // Set your minimum scroll amount here
$(window).scroll(
function() {
var t = $(window).scrollTop();
if (t > min_scroll) {
// define your scroll CSS here
header.css({position: "relative"});
ad.css({position: "relative"});
} else {
// define your non-scrolled CSS here
header.css({position: "fixed"});
ad.css({position: "absolute"});
}
}
);