Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

117
Views
Animar la altura del rect en la primera carga y al pasar el mouse / hacia afuera

es la primera vez que uso Vue.js y necesito hacer una animación muy simple en la primera carga del componente.

Este es mi punto de partida :

 <template> <div id="app"> <div class="rect" /> </div> </template> <script> export default { name: "App", components: {}, }; </script> <style lang="scss"> #app { border: 2px solid black; width: 200px; height: 300px; } #app:hover { .rect { background-color: tomato; height: 0%; } } .rect { transition: all 1s ease; background-color: tomato; width: 100%; height: 100%; } </style>

Ahora, quiero que en la primera carga, la altura del rectángulo rojo pase de 0% a 100% en 2 segundos y luego debería comportarse como ahora, de modo que al pasar el mouse, la altura se convierta en 0, al pasar el mouse fuera 100%. Para hacerlo, creo una variable isFirstLoad y cambio entre las dos nuevas clases height-0 y height-100 .

Aquí el código:

 <template> <div id="app"> <div class="rect" :class="{ 'height-100': isFirstLoad }" /> </div> </template> <script> export default { name: "App", components: {}, data: function () { return { isFirstLoad: true, }; }, mounted() { setTimeout(() => { this.isFirstLoad = false; }, 2000); }, }; </script> <style lang="scss"> #app { border: 2px solid black; width: 200px; height: 300px; .height-0 { height: 0%; } .height-100 { height: 100%; } } #app:hover { .rect { background-color: tomato; height: 0%; } } .rect { transition: all 1s ease; background-color: tomato; width: 100%; // height: 100%; } </style>

Funciona en la primera carga, pero luego, la altura recta siempre es 0%. Supongo que porque establezco height-0 siempre. ¿Cómo puedo arreglar?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Prueba como el siguiente fragmento:

 new Vue({ el: '#app', data() { return { isFirstLoad: true, } }, methods: { setHeight(toggle) { this.isFirstLoad = toggle; } }, mounted() { setTimeout(() => { this.isFirstLoad = false; }, 2000); } }) Vue.config.productionTip = false Vue.config.devtools = false
 #app { border: 2px solid black; width: 200px; height: 300px; } #app .height-0 { height: 0%; } #app .height-100 { height: 100%; } #app:hover .rect { background-color: tomato; } .rect { transition: all 1s ease; background-color: tomato; width: 100%; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script> <div id="app" @mouseover="setHeight(true)" @mouseleave="setHeight(false)"> <div class="rect" :class="isFirstLoad ? 'height-100' : 'height-0'"> </div> </div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!