为什么不使用ngshow(angularjs)增加大小的尺寸?

发布于 2025-01-25 04:31:51 字数 2763 浏览 6 评论 0 原文

我有这个下拉列表,我希望高度被动画。我正在使用Max-Height来实现这一目标,并且有点有效,但是当它扩展时,它不会进行过渡。如果我降低尺寸(即返回),则它的过渡就可以了。

我有这个 pen 用我正在使用的html和css(更少)。动画在那里不起作用,但代码与我在下一个GIF中的代码相同。

第一个菜单的内容是“动态”的,因为它们可以是1、2或3,因此我使用不同类别定义了不同的高度。

这是CSS:

.content-management-dropdown {
  position: absolute;
  margin-top: 1rem !important;
  top: 2;
  right: 2.5rem;
  width: 17rem;
  box-shadow: 0 0.6rem 1.2rem rgba(0, 0, 0, 0.175);
  background-color: #ffffff;
  overflow: hidden;

  .menu-primary {
    width: 100%;

    &.ng-hide-remove {
      position: absolute;
      transform: translateX(-110%);
    }

    &.ng-hide-remove-active {
      transform: translateX(0%);
      transition: all 500ms ease;
      // max-height: 3.7rem;

      // &.menu-2-item {
      //   max-height: calc(3.7rem * 2);
      // }

      // &.menu-3-item {
      //   max-height: calc(3.7rem * 3);
      // }
    }

    &.ng-hide-add {
      position: absolute;
      max-height: 3.7rem;
      &.menu-2-item {
        max-height: calc(3.7rem * 2);
      }

      &.menu-3-item {
        max-height: calc(3.7rem * 3);
      }
    }

    &.ng-hide-add-active {
      transform: translateX(-110%);
      transition: all 500ms ease;
      max-height: 27rem;
    }
  }

  .menu-secondary {
    &.ng-hide-remove {
      transform: translateX(110%);
      transition: all 500ms ease;
    }

    &.ng-hide-remove-active {
      transform: translateX(0%);
      transition: all 500ms ease;
    }

    &.ng-hide-add {
      max-height: 27rem;
    }

    &.ng-hide-add-active {
      transform: translateX(110%);
      transition: all 500ms ease;

      max-height: 3.7rem;

      &.menu-2-item {
        max-height: calc(3.7rem * 2) !important;
      }

      &.menu-3-item {
        max-height: calc(3.7rem * 3) !important;
      }
    }
  }

  ul {
    padding: 0;
  }

  &__list-item {
    padding: 0.6rem 0;
    list-style: none;
    border-bottom: 0.1rem solid black;
    transition: background 500ms;
    cursor: pointer;
    display: flex;
    align-items: center;

    & > * {
      display: block;
      padding: 0.3rem 2rem;
      text-transform: none !important;
    }

    &:last-child {
      border-bottom: none;
    }

    &:hover {
      background-color: #edf1f5;
    }
  }
}

我还在使用 this 视频作为动画的参考。

感谢您的帮助

I have this dropdown that I want the height to be animated. I'm using max-height to achieve this and it kinda works, but when it expands it won't do the transition. If I reduce the size (i.e. go back) then it transitions just fine.

I have this pen with the html and css (less) that I'm using. The animations aren't working there but the code is the same as what I have in the next gif.

Gif

The contents of the first menu are "dynamic" as in they can be either 1, 2 or 3, hence the different heights that I have defined with different classes.

Here is the css:

.content-management-dropdown {
  position: absolute;
  margin-top: 1rem !important;
  top: 2;
  right: 2.5rem;
  width: 17rem;
  box-shadow: 0 0.6rem 1.2rem rgba(0, 0, 0, 0.175);
  background-color: #ffffff;
  overflow: hidden;

  .menu-primary {
    width: 100%;

    &.ng-hide-remove {
      position: absolute;
      transform: translateX(-110%);
    }

    &.ng-hide-remove-active {
      transform: translateX(0%);
      transition: all 500ms ease;
      // max-height: 3.7rem;

      // &.menu-2-item {
      //   max-height: calc(3.7rem * 2);
      // }

      // &.menu-3-item {
      //   max-height: calc(3.7rem * 3);
      // }
    }

    &.ng-hide-add {
      position: absolute;
      max-height: 3.7rem;
      &.menu-2-item {
        max-height: calc(3.7rem * 2);
      }

      &.menu-3-item {
        max-height: calc(3.7rem * 3);
      }
    }

    &.ng-hide-add-active {
      transform: translateX(-110%);
      transition: all 500ms ease;
      max-height: 27rem;
    }
  }

  .menu-secondary {
    &.ng-hide-remove {
      transform: translateX(110%);
      transition: all 500ms ease;
    }

    &.ng-hide-remove-active {
      transform: translateX(0%);
      transition: all 500ms ease;
    }

    &.ng-hide-add {
      max-height: 27rem;
    }

    &.ng-hide-add-active {
      transform: translateX(110%);
      transition: all 500ms ease;

      max-height: 3.7rem;

      &.menu-2-item {
        max-height: calc(3.7rem * 2) !important;
      }

      &.menu-3-item {
        max-height: calc(3.7rem * 3) !important;
      }
    }
  }

  ul {
    padding: 0;
  }

  &__list-item {
    padding: 0.6rem 0;
    list-style: none;
    border-bottom: 0.1rem solid black;
    transition: background 500ms;
    cursor: pointer;
    display: flex;
    align-items: center;

    & > * {
      display: block;
      padding: 0.3rem 2rem;
      text-transform: none !important;
    }

    &:last-child {
      border-bottom: none;
    }

    &:hover {
      background-color: #edf1f5;
    }
  }
}

I also was using this video as reference for the animations.

Thanks for the help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乖乖哒 2025-02-01 04:31:51

终于最终弄清楚了。
我更改了CSS,辅助菜单是唯一控制高度的菜单。然后我对高度遇到了问题,事实证明,其中一个高度只是被较小的高度覆盖。

这是菜单的最后CSS:

.menu-primary {
    width: 100%;

    &.ng-hide-remove {
      position: absolute;
      transform: translateX(-110%);
    }

    &.ng-hide-remove-active {
      transform: translateX(0%);
      transition: all 500ms ease;
    }

    &.ng-hide-add {
      position: absolute;
    }

    &.ng-hide-add-active {
      transform: translateX(-110%);
      transition: all 500ms ease;
    }
  }

  .menu-secondary {

    &.ng-hide-remove {
      transform: translateX(110%);
      max-height: 3.7rem;

      &.menu-2-item {
        max-height: calc(3.7rem * 2);
      }

      &.menu-3-item {
        max-height: calc(3.7rem * 3);
      }
    }

    &.ng-hide-remove-active {
      transform: translateX(0%);
      transition: all 500ms ease;
      max-height: 27rem !important;
    }

    &.ng-hide-add {
      max-height: 27rem;
    }

    &.ng-hide-add-active {
      transform: translateX(110%);
      transition: all 500ms ease;

      max-height: 3.7rem;

      &.menu-2-item {
        max-height: calc(3.7rem * 2);
      }

      &.menu-3-item {
        max-height: calc(3.7rem * 3);
      }
    }

Finally ended up figuring it out.
I changed the css and the secondary menu is the only one that controls the heights. Then I had an issue with the heights and it turns out one of the heights was just being overwritten with a smaller height.

Here is the final css for the menus:

.menu-primary {
    width: 100%;

    &.ng-hide-remove {
      position: absolute;
      transform: translateX(-110%);
    }

    &.ng-hide-remove-active {
      transform: translateX(0%);
      transition: all 500ms ease;
    }

    &.ng-hide-add {
      position: absolute;
    }

    &.ng-hide-add-active {
      transform: translateX(-110%);
      transition: all 500ms ease;
    }
  }

  .menu-secondary {

    &.ng-hide-remove {
      transform: translateX(110%);
      max-height: 3.7rem;

      &.menu-2-item {
        max-height: calc(3.7rem * 2);
      }

      &.menu-3-item {
        max-height: calc(3.7rem * 3);
      }
    }

    &.ng-hide-remove-active {
      transform: translateX(0%);
      transition: all 500ms ease;
      max-height: 27rem !important;
    }

    &.ng-hide-add {
      max-height: 27rem;
    }

    &.ng-hide-add-active {
      transform: translateX(110%);
      transition: all 500ms ease;

      max-height: 3.7rem;

      &.menu-2-item {
        max-height: calc(3.7rem * 2);
      }

      &.menu-3-item {
        max-height: calc(3.7rem * 3);
      }
    }

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文