[英]Move large image inside smaller visible container
I am trying to do something basic (beginner in programming). 我正在尝试做一些基本的东西(编程初学者)。 I try to take a large image and a smaller container , and move the image
up
or down
inside while the user scrolls. 我尝试拍摄大图像和较小的容器 ,并在用户滚动时
up
或down
移动图像。
Move the yellow up
or down
while the user can see the red in the same position (kept in doc flow). up
或down
移动黄色 up
同时用户可以看到相同位置的红色 (保留在文档流程中)。
If i create an image using this : 如果我用这个创建一个图像:
<div class="cvrContainer top left">
<div class="cvrPhoto" id="photo0" style="background-image: url(https://picsum.photos/900/850);"></div>
</div>
cvrPhoto
to be larger then cvrContainer
say 200% ? cvrPhoto
设置为更大,然后cvrContainer
说200%? JS
while keeping overflow hidden. JS
向上/向下移动它。 I do not ask how to calculate, only how to set it and move the only yellow inside 我不问如何计算,只是如何设置它并移动内部唯一的黄色
If you want to create simple parallax effect, you can achieve this effect by position fixed, add position: fixed
on .cvrPhoto
div. 如果要创建简单的视差效果,可以通过固定位置来实现此效果,添加
position: fixed
在.cvrPhoto
div上。
.cvrContainer { padding: 30px; width: 100%; height: 2000px; overflow: auto; background: url(https://picsum.photos/900/850); } .cvrPhoto { height: 300px; width: 200px; position: fixed; top: 57px; background: yellow; }
<div class="cvrContainer style=" background-image: url(https://picsum.photos/900/850); ""> <div class="cvrPhoto"></div> </div>
I solved it by using css for the inner image (not background image but img
tag) : 我通过使用css为内部图像解决了它(不是背景图像,而是
img
标签):
.prlxPhoto
{
position: absolute;
left: 50%;
top: 50%;
-webkit-transform: translateY(-50%) translateX(-50%);
}
and move it left/right for example with : 并向左/向右移动,例如:
var e = document.getElementById("1");
e.style.marginLeft = equotion+'px';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.