我在JS和前端方面是一个完全的初学者.我在一个网站上工作,我在这个div中有一张ID为main-image
的图像.
当用户向下滚动图像时,我希望它慢慢向左滚动,然后删除图像.
var x = 0;
var screenWidth = window.innerWidth;
window.onscroll = function() {
var box = document.getElementById("main-image");
setInterval(function() {
if (x <= screenWidth) {
x++;
box.style.left = x + "px";
} else {
box.style.display = "none";
}
}, 10);
}
.site-header {
background-image: url("https://images.pexels.com/photos/2159065/pexels-photo-2159065.jpeg?auto=compress&cs=tinysrgb&fit=crop&h=627&w=1200");
height: 100vh;
background-repeat: no-repeat;
background-size: cover;
justify-content: center;
position: relative;
}
#main-image {
position: marker;
left: 0;
transition: ease-out;
}
<div class="container-fluid site-header" id="main-image">
<div class="image-on-text-container bg-secondary">
<span class="site-brand"></span>
</div>
</div>
我为这个写了这个 playbook ,但进展很糟糕.我希望它移动得慢一些,也许会有一些效果,但我不知道怎么做.