简体   繁体   English

css - 单击显示更多按钮时如何使用缓入

[英]css - how to use ease-in when clicking show more button

I want to have an animation of ease-in/out for 3 seconds when clicking show more, but I find that I cna't achieve it since I am using overflow: hidden and -webkit-line-clamp: 2;我想在点击显示更多时有一个 3 秒的缓入/缓出动画,但我发现我无法实现它,因为我使用了overflow: hidden-webkit-line-clamp: 2;

Is there other ways to do so?还有其他方法吗?
在此处输入图片说明

HelloWorlfd.vue你好世界

<template>
  <div class="item">
    <div :class="{ description: true, 'description--hidden': isShowMore }">
      Lorem Ipsum is simply dummy text of the printing and typesetting industry.
      Lorem Ipsum has been the industry's standard dummy text ever since the
      1500s, when an unknown printer took a galley of type and scrambled it to
      make a type specimen book. It has survived not only five centuries, but
      also the leap into electronic typesetting, remaining essentially
      unchanged. It was popularised in the 1960s with the release of Letraset
      sheets containing Lorem Ipsum passages, and more recently with desktop
      publishing software like Aldus PageMaker including versions of Lorem
      Ipsum.
    </div>
    <button class="show-more-btn" @click="toggleShowMore">
      <span>show More</span>
    </button>
  </div>
</template>
<script>
export default {
  components: {},
  data() {
    return {
      isShowMore: false,
    };
  },
  methods: {
    toggleShowMore() {
      this.isShowMore = !this.isShowMore;
    },
  },
};
</script>
<style scoped lang="scss">
.item {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 558px;
  height: auto;
  .description {
    margin-bottom: 36px;
  }
  .description--hidden {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2; /* number of lines to show */
    -webkit-box-orient: vertical;
  }
  .show-more-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 600;
    background-color: transparent;
    border: none;
    &:hover {
      cursor: pointer;
    }
    span {
      padding: 0 0.5rem;
    }
  }
}
</style>

CodeSandbox:代码沙盒:
https://codesandbox.io/s/magical-https-ukev7?file=/src/components/HelloWorld.vue:0-1726 https://codesandbox.io/s/magical-https-ukev7?file=/src/components/HelloWorld.vue:0-1726

As you stated, -webkit-line-clamp: 2 may be a reason the animation won't play.正如您所说, -webkit-line-clamp: 2可能是动画无法播放的原因。 However, overflow: hidden should not prevent this if we use the animation property with a keyframe, to delay its timing.但是,如果我们使用具有关键帧的动画属性来延迟其计时,则overflow: hidden不应阻止这种情况。

In addition we can create the dropdown effect by using the transition property, and max-height.此外,我们可以通过使用 transition 属性和 max-height 来创建下拉效果。

Below is a version of your css, that will get you the transition you want :)以下是您的 css 版本,它将为您提供所需的过渡效果:)

You can adjust the property values for height, and timings for animation and transition, as you see fit.您可以根据需要调整高度的属性值以及动画和过渡的时间。

Let me know if this helps :) !如果这有帮助,请告诉我:)!

.description {
    margin-bottom: 36px;
    max-height: 500px;
    transition: all ease-in 0.3s;
    overflow: auto;
  }
  @keyframes delay-overflow {
    from { overflow: auto; }
  }
  .description--hidden {
    max-height: 40px;
    overflow:hidden;
    animation: 1s delay-overflow;
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM