Javascript 滚动时视差效果不适用于背景色
我的视差效果有问题。我有一张照片,在这张照片的背面我有一种颜色。下面是我的htmlJavascript 滚动时视差效果不适用于背景色,javascript,jquery,parallax,Javascript,Jquery,Parallax,我的视差效果有问题。我有一张照片,在这张照片的背面我有一种颜色。下面是我的html <div class="rectangle background-medium-blue header-stage-medium-blue-rectangle"></div> <div class="image"> <img class="img" src="stage-allviewports-4x3.jpg" width="1450" height="10
<div class="rectangle background-medium-blue header-stage-medium-blue-rectangle"></div>
<div class="image">
<img class="img" src="stage-allviewports-4x3.jpg" width="1450" height="1089" />
</div>
css
请发布CSS。@Passele我添加了CSS请发布CSS。@Passele我添加了CSS
var parallax= document.querySelector(".header-stage-medium-blue-rectangle");
window.addEventListener("scroll", function() {
var scrolledHeight= window.pageYOffset;
parallax.style.top= (scrolledHeight * 0.2) + "px";
});
.header-stage-medium-blue-rectangle {
position: absolute;
background-color: red;
right: 0px;
top: 302px;
}