Quiero tener una animación de entrada/salida gradual durante 3 segundos al hacer clic en mostrar más, pero encuentro que no puedo lograrlo ya que estoy usando overflow: hidden y -webkit-line-clamp: 2;
HolaMundo.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> Caja de arena de código:
https://codesandbox.io/s/magical-https-ukev7?file=/src/components/HelloWorld.vue:0-1726
Como dijiste, -webkit-line-clamp: 2 puede ser una razón por la cual la animación no se reproducirá. Sin embargo, overflow: hidden no debería evitar esto si usamos la propiedad de animación con un fotograma clave, para retrasar su temporización.
Además, podemos crear el efecto desplegable utilizando la propiedad de transición y la altura máxima.
A continuación se muestra una versión de su css, que le dará la transición que desea :)
Puede ajustar los valores de propiedad para la altura y los tiempos para la animación y la transición, como mejor le parezca.
Déjeme saber si esto ayuda :) !
.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; }