其他分享
首页 > 其他分享> > 进阶版css点击按钮动画

进阶版css点击按钮动画

作者:互联网

1. html

<div class="menu-wrap">
    <input type="checkbox" class="toggler">
    <div class="hamburger"><div></div></div>
    <div class="menu">
      <div>
        <ul>
          <li><a href="#">Home</a></li>
          <li><a href="#">About</a></li>
          <li><a href="#">Serices</a></li>
          <li><a href="#">Contact</a></li>
        </ul>
      </div>
    </div>
  </div>

2. css

.menu-wrap {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1;
}
.menu-wrap .toggler {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  /* 控制光标的类型 */
  cursor: pointer;
  width: 60px;
  height: 60px;
  opacity: 0;
}
.menu-wrap .hamburger {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  width: 60px;
  height: 60px;
  padding: 1rem;
  background: var(--primary--color);
  display: flex;
  justify-content: center;
  align-content: center;
}
/* hamburger line */
.menu-wrap .hamburger > div {
  position: relative;
  top: 15px;
  flex: none;
  width: 100%;
  height: 2px;
  background: #fff;
  transition: all 0.4s ease;
}

/* hamburger liner -- top & bottom */
.menu-wrap .hamburger > div:before,
.menu-wrap .hamburger > div:after{
  content: '';
  position: absolute;
  z-index: 1;
  background: #fff;
  width: 100%;
  height: 2px;
  top: -10px;
}

.menu-wrap .hamburger > div:after {
  top: 10px;
}

/* toggler animation */

.menu-wrap .toggler:checked + .hamburger > div {
  transform: rotate(135deg);
}
/* turn linex into */
.menu-wrap .toggler:checked + .hamburger > div:before,
.menu-wrap .toggler:checked + .hamburger > div:after{
  top: 0px;
  transform: rotate(90deg);
}
.menu-wrap .toggler:checked:hover + .hamburger > div {
  transform: rotate(225deg);
}

3 . 重点

:checked 选择器匹配每个已被选中的 input 元素(只用于单选按钮和复选框)。

标签:动画,hamburger,进阶,menu,top,toggler,wrap,div,css
来源: https://www.cnblogs.com/wqddmghsdfh/p/16061956.html