【发布时间】:2016-03-27 17:11:01
【问题描述】:
我有以下:
一个.circle,里面有一个.object。请参阅下面的代码(并查看全屏示例)。
我希望.object 来自底部(动画),所以圆圈可能是overflow: hidden;,但我希望.object 从顶部出来。最终结果见this image。
简而言之:.object 只能与底部的.circle 相同。
所以我认为svg 掩码(底部边界半径为 50% 的正方形)可以解决问题。到目前为止,还没有运气让它发挥作用。
我错过了什么吗?我没有正确使用它吗? SVG 不能用来屏蔽div 元素吗?或者对于这个问题还有其他明显的解决方案吗?
body,
html {
margin: 0;
padding: 0;
height: 100%;
}
.container {
background: gold;
width: 100%;
height: 100%;
position: relative;
}
.circle {
background: LightCoral;
width: 300px;
height: 300px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border-radius: 50%;
clip-path: url(#clipping);
}
.object {
background: DeepSkyBlue;
width: 150px;
height: 350px;
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
}
svg {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<div class="container">
<div class="circle">
<div class="object"></div>
<svg xmlns="http://www.w3.org/2000/svg" width="300" height="300" viewBox="0 0 300 300">
<defs>
<clipPath id="clipping">
<path class="cls-1" d="M0,0H300V150H0V0ZM300,150A150,150,0,0,1,0,150" />
</clipPath>
</defs>
</svg>
</div>
</div>
【问题讨论】:
-
不完全确定你想要完成什么 - 你能澄清一下吗?
-
您可以在 SVG 中使用蒙版,稍后将发布代码。
-
@MichaelMullany 我添加了我想要实现的最终结果的图像,这是否足够清楚?
-
你的圆圈和蓝色对象需要是 HTML 元素吗?如果所有元素都是 SVG 元素,这将非常容易。