[英]CSS: Using transform to move an element to a specific place on the DOM
I have an image (svg) that start out in the middle of the page on load.我有一个图像(svg),在加载时从页面中间开始。 As the user scrolls down, I want to have that image drift up and to the left so that it eventually gets pinned in the top left corner.
当用户向下滚动时,我想让该图像向上和向左漂移,以便最终固定在左上角。
I tried using translate with the scroll number but I feel like it's a guessing game on where the image will end up and what path it takes.我尝试使用带有滚动编号的翻译,但我觉得这是一个关于图像将在哪里结束以及它采用什么路径的猜谜游戏。 Here is what I had so far.
这是我到目前为止所拥有的。
window.addEventListener('scroll', function(evt) { let image = document.getElementById('image'); let scrollY = window.pageYOffset; // how do I use the scrollY to accomplish this? image.style.transform =??
<div style="text-align: center; background: blue; height: 900px;"> <img id="image" style=" margin-top: 200px; " src="mySvg.svg" /> </div>
for working document.getElementById('image');用于工作 document.getElementById('image'); need to have is corresponded element.
需要有对应的元素。
<img id="image" style=" margin-top: 200px; " src="mySvg.svg" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.