我怎样才能产生过渡效果

问题描述 投票:-5回答:1

我需要帮助transition效果。我有代码块,我想添加悬停transition效果。我该怎么做?

.mockup img {
  cursor: pointer;
}

.mockup img:last-child {
  display: none;
}

.mockup:hover img:first-child {
  display: none;
}

.mockup:hover img:last-child {
  display: inline-block;
}
<div class="row">
  <div class="col-lg-8 mx-auto mockup">
    <img src="http://lorempixel.com/output/animals-q-c-640-480-9.jpg">
    <img src="http://lorempixel.com/output/animals-q-c-640-480-7.jpg">
  </div>
</div>
html css transition
1个回答
0
投票

遗憾的是,您无法向显示属性添加转换,但可以使用不透明度或可见性替换它

所以您的代码可以替换为:

.mockup img {
    cursor: pointer;
    transition: all 0.3s ease;
}

.mockup img:last-child {
    opacity: 0;
    visibility: hidden;
}

.mockup:hover img:first-child {
    opacity: 0;
    visibility: hidden;
}

.mockup:hover img:last-child {
    opacity: 1;
    visibility: visible;
}
© www.soinside.com 2019 - 2024. All rights reserved.