首页 > 解决方案 > 动画右侧的关闭侧面板

问题描述

所以我的右侧边栏动画很好地进入了,但是我现在如何动画出来它只是在没有任何动画的情况下关闭?

.calendarQuickpanelContainer {
    animation: animateopen 0.6s;
    bottom: 0;
    display: none;
    position: fixed;
    top: 0;
    right: 0;
    width: 462px;
    z-index: 100;
}

.calendarQuickpanel {
    display: block;
}

@keyframes animateopen {
    0% {
      right: -462px;
      opacity: 0;
    }

    100% {
      right: 0;
      opacity: 1;
    }
}

谢谢

标签: csscss-animations

解决方案


动画不是很好,这里最好使用过渡。你有更好的控制,因为你可以使用一个类来切换状态。

function toggleFunction() {
  var element = document.getElementById("sidebar");
  element.classList.toggle("active");
}
#sidebar {
  background: lightblue;
  width: 250px;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  transform: translateX(-260px);
  opacity: 0;
  transition: transform 1s, opacity 1s;
}

#sidebar.active {
  transform: translateX(0px);
  opacity: 1;
}

button {
  float: right;
  margin: 32px;
}
<div id="sidebar">
</div>
<button onclick="toggleFunction()">toggle sidebar</button>


推荐阅读