使用您的 html,这里是 css:
.menu, .headerimg, .content {
width: 100%;
}
.menu {
background: red;
height: 50px;
position: fixed;
top: 0;
}
.headerimg {
background: yellow;
height: 100px;
position: fixed;
top:50px;
z-index: -2;
}
.content {
height: 1000px;
background: gray;
z-index:50;
margin-top: 160px;
}
现在要让.headerimg
滚动速度慢于.content
,请使用 Jquery
$(document).ready(function() {
window.onscroll = function () {
n = Math.ceil($("body").scrollTop() / 4);
$(".headerimg").css("-webkit-transform", "translateY(-" + n + "px)");
$(".headerimg").delay(1300).css("-moz-transform", "translateY(-" + n + "px)");
}
})
http://jsfiddle.net/akurtula/3w9Dv/1