【问题标题】:CSS animated hamburger menu to XCSS动画汉堡菜单到X
【发布时间】:2017-12-01 17:30:52
【问题描述】:

我用 CSS 制作了自己的汉堡菜单。我想用 flexbox 解决它。所以我的 html/css 部分已经完成,看起来像这样:

angular.module("myApp", []).controller("myController", function($scope) {
  $scope.animateHamburger = function() {
    // ANIMATION
    console.log("animate hamburger to cross and back to hamburger");
  }
});
.cAnimatedExpander {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  height: 20px;
  margin-right: 10px;
  cursor: pointer;
}

.cAnimatedExpander span {
  height: 2px;
  width: 20px;
  background-color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myController" class="cAnimatedExpander" ng-click="animateHamburger()">
  <span></span>
  <span></span>
  <span></span>
</div>

所以现在我想要一个带有 css 的动画,就像这个例子(第一个 Slider):https://jonsuh.com/hamburgers/

我在互联网上找到了一些很好的教程,但我想在我的解决方案中使用没有 flexbox。希望得到一些帮助。

【问题讨论】:

  • 我不明白,你在那个链接上有你需要的一切,只需解析他们的代码并使用你需要的部分
  • 仅仅为了它而使用 Flexbox 并没有什么意义。我看不出你为什么要使用它。

标签: jquery html css angularjs flexbox


【解决方案1】:

这应该可以解决您的问题。

angular.module("myApp", []).controller("myController", function($scope) {
  $scope.animateHamburger = function() {
    // ANIMATION
    console.log("animate hamburger to cross and back to hamburger");
    $scope.isActive = !$scope.isActive;
  }
  
});
.cAnimatedExpander {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  height: 20px;
  margin-right: 10px;
  cursor: pointer;
}

.cAnimatedExpander span {
  height: 2px;
  width: 20px;
  background-color: blue;
  transition-duration: 1s;
}

.cross span.top {
    transform: translate(0px, -4px) rotate(45deg);
    transition-duration: 1s;
    transform-origin: left;
}

.cross span.middle {
  opacity: 0;
  transition-duration: 1s;
}

.cross span.bottom {
    transform: translate(0px, -4px) rotate(-45deg);
    transition-duration: 1s;
    transform-origin: left;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myController" ng-class="{'cross': isActive}" class="cAnimatedExpander" ng-click="animateHamburger()">
  <span class="top"></span>
  <span class="middle"></span>
  <span class="bottom"></span>
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-28
    • 1970-01-01
    • 1970-01-01
    • 2021-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多