简体   繁体   English

父div上的border-radius打破了视角/子div上的translateZ

[英]border-radius on parent div breaks perspective / translateZ on child

I followed a tutorial for a css-only scrolling parallax effect, but now I want to put the image inside a circle. 我遵循了有关纯css滚动视差效果的教程,但是现在我想将图像放置在一个圆圈内。

So I... 所以我...

1) set the parent div ("wrapper") to my chosen dimensions, 1)将父div(“包装器”)设置为我选择的尺寸,

2) set the parent to overflow-hidden, (so far so good, the parallax effect still works inside my "clipped" box), 2)将父级设置为溢出隐藏,(到目前为止,效果很好,视差效果仍在我的“裁剪”框中),

3) ...but when I set a border-radius of any kind, it breaks the parallax effect, freezing the image in place when I scroll. 3)...但是当我设置任何类型的边框半径时,它会破坏视差效果,并在滚动时将图像冻结在适当的位置。

Here's my pen: https://codepen.io/iiiDaNiii/pen/eEBEyY with the parallax effect working inside a square div called "wrapper." 这是我的笔: https : //codepen.io/iiiDaNiii/pen/eEBEyY ,其视差效果在称为“包装纸”的方形div内起作用。 If you try to add a border-radius, it breaks the parallax effect. 如果尝试添加边界半径,则会破坏视差效果。

.html {
  overflow:hidden;
}

.scroll {
  right:0px;
  overflow-y:auto;
  overflow-x:hidden;
  position:absolute;
  height:100vh;
  width:100vw;
  -webkit-overflow-scrowling: touch;
  -webkit-perspective: 1px;
  perspective: 1px;
  perspective-origin: 0% 0%;
  margins: 0px;
  padding: 0px;
  top:0px;
}

.wrapper {
  background-color:blue;
  position:relative;
  height:20em;
  width:20em;
  overflow:hidden;
}

.image {
  position:relative;
  height:vh;
  width:vw;
  -webkit- transform: translateZ(-1px) scale(2);
  transform: translateZ(-1px) scale(2);
  transform-origin: 50% 0;

}

.space{
  position:relative;
  background-color:white;
  height:2000px;
}

Any rad thoughts? 拉德有什么想法吗?

Update / clarification: I want whatever is outside of the circle to be transparent.... so that the parallax-circle-image could sit on top of ie another image. 更新/说明:我希望圆之外的任何东西都是透明的...。以便视差圆图像可以位于另一个图像之上。

I believe I've found a solution. 我相信我已经找到了解决方案。

I've added a pseudo-class to the .wrapper element and applied a solid box-shadow to it with a border-radius of 5px, which maintains the parallax effect and also gives rounded corners. 我在.wrapper元素中添加了一个伪类,并.wrapper应用了一个实心的box-shadow ,其border-radius为5px,这保持了视差效果并给出了圆角。

So, add the following selector to your css: 因此,将以下选择器添加到CSS中:

.wrapper:before
{
    position: absolute;
    content: '';
    top: 0; left: 0;
    right: 0; bottom: 0;
    border-radius: 5px;
    z-index: 5;
    box-shadow: 0 0 0 10px white;
}

I created a live Fiddle here . 我在这里创建了一个现场小提琴。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM