简体   繁体   English

从左到右逐渐覆盖一个图像

[英]Gradually cover one image with other from left to right

Is it possible to cover one image with other gradually from left to right?是否可以从左到右逐渐覆盖一个图像? Something like loading one image over another.就像将一个图像加载到另一个图像上一样。 Or you can imagine progress bar with image instead of line.或者您可以想象带有图像而不是线条的进度条。 I hope you understand me.我希望你理解我。

I tried something like below but I don't want that fading effect and it's not changing color(image) from left to right.我尝试了类似下面的方法,但我不想要那种褪色效果,而且它不会从左到右改变颜色(图像)。

 .bgImg { width: 500px; height: 500px; background-image: url(https://s14.postimg.org/unjnz24ld/rkfe2i3pdqqx.jpg); background-repeat: no-repeat; -webkit-transition: background-image 2s linear; -moz-transition: background-image 2s linear; -ms-transition: background-image 2s linear; transition: background-image 2s linear; } .bgImg:hover { background-image: url(https://s14.postimg.org/mi1m10iy9/gre.jpg); }
 <div class="bgImg"></div>

You can use gradient for colors as background and simply animate background-size then use your text inside html and no need to use it within the image:您可以使用渐变颜色作为背景并简单地设置background-size动画,然后在 html 中使用您的文本,而无需在图像中使用它:

 .bgImg { width: 500px; height: 150px; text-align:center; font-size:30px; background: linear-gradient(red,red), yellow; background-size:0% 100%; background-repeat: no-repeat; transition:2s linear; } .bgImg:hover { background-size:100% 100%; }
 <div class="bgImg"> Some text</div>

And if you want to still use your image consider animating background-position like this:如果您仍然想使用您的图像,请考虑像这样设置background-position动画:

 .bgImg { width: 500px; height: 500px; background-image: url(https://picsum.photos/id/10/500/500), url(https://picsum.photos/id/15/500/500); background-repeat: no-repeat; background-position:500px 0,0 0; transition: 2s linear; } .bgImg:hover { background-position:0 0,0 0; }
 <div class="bgImg"></div>

Or consider the use of pseudo element like below:或者考虑使用如下伪元素:

 .bgImg { width: 500px; height: 500px; background: url(https://picsum.photos/id/15/500/500) center/cover; position:relative; } .bgImg:before { content:""; position:absolute; top:0; left:100%; right:0; bottom:0; background: url(https://picsum.photos/id/10/500/500) right/auto 100% no-repeat; transition: 2s linear; } .bgImg:hover:before { left:0; }
 <div class="bgImg"></div>

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

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