的劇本給我一個錯誤,所以我改變
var abouttop = document.getElementById("about").getBoundingClientRect().height;
然後我決定不使用background-attachment
但transforms
。 此外,您錯過了文本容器的id="about"
。 我不使用JQuery所以這裏有一些工作js(對不起,因爲混亂):
var pos = 0;
var imageControl = function(e) {
var scrollposition = document.documentElement.scrollTop;
var abouttop = document.getElementById("about").getBoundingClientRect().height;
var scrollBottom = jQuery(window).scrollTop() + jQuery(window).height();
var image_height = document.getElementById("image").getBoundingClientRect().height;
// console.log(scrollBottom);
if (scrollBottom < abouttop) {
pos = scrollposition;
} else if (scrollBottom > abouttop) {
//pos = abouttop-image_height;
}
console.log(pos);
document.getElementById("image").style.transform = "translateY(" + pos + "px)";
};
jQuery(window).scroll(imageControl);