CSS(或非)动画图像在鼠标悬停时变得透明,然后再次变得不透明

标签 css image transparency

嘿伙计们要问了,我必须制作一张有点透明的图片(比如不透明度 0,4),然后它的大小增加 2 倍,然后再次变得不透明(不透明度 1) 并且文本一直没有改变它的位置。

img  {
         opacity: 1;
         width: 250;
         }
         img:hover {
    opacity: 0.4;
    filter: alpha(opacity=40);
        width: 500px; 
        transition-property: width;  
  transition-duration: 4s;

                         }

我只为尺寸增加和透明度制作了一个 css 代码,但是不知道如何在我的 4 秒动画后再次使它的不透明度为 1,也不知道如何在图像尺寸增加后使文本保持在相同的位置。

最佳答案

这是一种解决方案,但如果没有更多信息,很难为您提供最佳答案。您只能使用 css 对悬停应用效果,这意味着一旦图片不再悬停,图片将恢复正常。如果您想要一个在 4 秒后自动恢复正常的解决方案,那么您应该使用 javascript。

.wrapper {
  width: 100%;
}
figure {
  display: inline-block;
  width: 120px; /* It has to be bigger than twice the size of your picture if you don't want the text to move */
}
img {
  width: 50px;
  height: auto;
  -webkit-transition: width, 0, 4s;
  transition: width, 0, 4s;
}
img:hover {
  width: 100px; /* twice the original size */
  opacity: .4;
}
.text {
  display: inline-block; /* so that your text is aligned with picture */
  vertical-align: top; /* so that your text doesn't move */
}
<div class="wrapper">
  <figure>
    <img src="http://lorempixel.com/100/100">
  </figure>
  <div class="text">
    Some text...
  </div>
</div>

关于CSS(或非)动画图像在鼠标悬停时变得透明,然后再次变得不透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26423166/

相关文章:

javascript - 使用 Javascript 制作一个关注按钮

html - z-index 和堆叠;从堆叠上下文中删除一个 child

android - 图像无法在 Android 7.0 (API 24) 上呈现

c# - C#中如何判断一个控件是否允许透明?

java - 如何使用 JDialog、JPanel 解决图形故障?

ffmpeg 在视频上覆盖透明动画 gif 并保持 gif 背景透明度

html - 如何让左边的div展开,右边的div宽度不变?

html - IE7、8、9 无法正确读取媒体查询。

html - 图库 block 在 WP Gallery 功能中 splinter 并融合在一起(Safari 和 Chrome 问题)

image - BASE64 到图像 Angular 2