【问题标题】:How do I create animation on hide/show?如何在隐藏/显示上创建动画?
【发布时间】:2015-04-04 05:34:09
【问题描述】:
    <div class="overlay"></div>

CSS:

    .overlay::after
     {
           position: fixed;
           top: 0;
           left: 0;
           width: 100%;
           content: "";
           z-index: -1;
           height: 100%;
           transition: all 0.5s ease-in-out;
           opacity: 0.5;
        }

        .popup::before
        {
           content: "";
           position: absolute;
           top: 0;
           left: 0;
           width: 100%;. 
           height: 100%;
           z-index: -1;
           transition: all 0.5s ease-in-out;
        }

这是我的覆盖类。我将此 div 显示为所有弹出窗口的掩码。但问题是即使我有过渡属性,它也没有显示任何动画。我想把它从左到右。我可以通过在隐藏时给予负左和在显示时给予正左来做到这一点。有没有什么办法可以在没有负面影响的情况下实现这一目标。有什么建议吗??

【问题讨论】:

标签: html css


【解决方案1】:

纯css可以是

*{box-sizing: border-box}
menu{
  position: absolute;
  top: 40px;
  left: -200px;
  width: 200px;
  display: block;
  background: black;
  color: white;
  transition: left .3s ease
}
menu li{padding: 10px 14px}
input:checked + menu{
  left: 0
}
label{cursor: pointer}
<label for=toogleMenu >Click to toggle the Menu </label>
<input type=checkbox id=toogleMenu hidden />
<menu>
  <li>Home</li>
  <li>Work</li>
  <li>Contact</li>
  <li>Help</li>
</menu>

使用变换

*{box-sizing: border-box}
menu{
  position: absolute;
  top: 40px;
  left: 0px;
  width: 200px;
  display: block;
  background: black;
  color: white;
  transform: translateX(-200px);
  transition: transform .3s ease
}
menu li{padding: 10px 14px}
input:checked + menu{
  transform: translateX(0);
}
label{cursor: pointer}
<label for=toogleMenu >Click to toggle the Menu </label>
<input type=checkbox id=toogleMenu hidden />
<menu>
  <li>Home</li>
  <li>Work</li>
  <li>Contact</li>
  <li>Help</li>
</menu>

【讨论】:

  • 谢谢坦博。所以我必须使用负向左来实现CSS的这种过渡效果..
  • 什么什么又拜托了
  • 我正在使用伪类。不分班。如果我将此属性应用于伪类,它也会移动弹出窗口。
猜你喜欢
  • 2013-12-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-25
  • 2016-02-02
  • 1970-01-01
相关资源
最近更新 更多