gpt4 book ai didi

javascript - 如何使不透明度逐渐缩放

转载 作者:行者123 更新时间:2023-11-28 15:04:40 25 4
gpt4 key购买 nike

我有一个 div,imgCover 与图像重叠。 imgCover 的背景设置为 rgba(255,255,255,.7),但我希望不透明度从 0.0 逐渐变为 1.0。

有没有办法让 imgCover 的不透明度在最左边为 0.0,然后在最右边为 1.0?

jsfiddle

#conveyorSec {
padding: 50px 0;
height: auto;
width: 100%;
}
#conveyorInner {
margin: 0 5%;
width: 90%;
height: 100%;
position: relative;
}
#conveyorInner img {
width: 100%;
height: auto;
}
#imgCover {
width: 40%;
height: 100%;
position: absolute;
background-color: rgba(255,255,255,.7);
right: 0;
top: 0;
z-index: 99;
}
<section id="conveyorSec">
<div id="conveyorInner">
<img src="https://media.istockphoto.com/photos/plant-growing-picture-id510222832?k=6&m=510222832&s=612x612&w=0&h=Pzjkj2hf9IZiLAiXcgVE1FbCNFVmKzhdcT98dcHSdSk=" alt="image">
<div id="imgCover"></div>
</div>
</section>

最佳答案

使用linear gradient而不是 background-color:

background: linear-gradient(to right, rgba(255,255,255,0), rgba(255,255,255,1)); 

#conveyorSec {
padding: 50px 0;
height: auto;
width: 100%;
}
#conveyorInner {
margin: 0 5%;
width: 90%;
height: 100%;
position: relative;
}
#conveyorInner img {
width: 100%;
height: auto;
}
#imgCover {
width: 40%;
height: 100%;
position: absolute;
background: linear-gradient(to right, rgba(255,255,255,0), rgba(255,255,255,1));
right: 0;
top: 0;
z-index: 99;
}
<section id="conveyorSec">
<div id="conveyorInner">
<img src="https://media.istockphoto.com/photos/plant-growing-picture-id510222832?k=6&m=510222832&s=612x612&w=0&h=Pzjkj2hf9IZiLAiXcgVE1FbCNFVmKzhdcT98dcHSdSk=" alt="image">
<div id="imgCover"></div>
</div>
</section>

关于javascript - 如何使不透明度逐渐缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49678354/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com