Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

78
Visualizações
Smooth max-height when removing

I have got a element I open using a transition so it's smooth, I then remove the set height when it is done so that the content can define the height.

However when closing the transition doesn't work, it's just an abrupt close.

Vue.component('test', {
  template: `<div>
  <a href="javascript:void(0)" @click="isActive = !isActive">Expand</a>
  <div ref="content" class="content"></div>
  </div>`,
  data() {
    return {
      isActive: false
    } 
  },
  mounted() {
   const _this = this;
    this.$refs.content.addEventListener('transitionend', function() {
      console.log('end');
      _this.$refs.content.classList.add('show');
      _this.$refs.content.style.maxHeight = null;
    })
  },
  watch: {
    isActive() {
      if (!this.isActive) {
        this.$refs.content.style.maxHeight = `${300}px`;
        return;
      }
      this.$refs.content.style.maxHeight = null;
      this.$refs.content.classList.remove('show');
    }
  }
});

new Vue({}).$mount('#app');
.content {
  background: red;
  height: 500px;
  display: block;
  transition: max-height .3s ease;
  max-height: 0;
}
.content.show {
  max-height: unset;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <test></test>
</div>

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda