• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

114
Views
Elemento animado con clase específica y propiedades CSS

Leí Jquery: Cómo verificar si el elemento tiene cierta clase/estilo css y funcionó -

 if ($(".box").css('display') == 'block') { console.log("message 2 - Div with box class exists and css Block exists") }

Leí cómo crear jquery deslizar hacia la izquierda y hacia la derecha y conseguí que funcionara:

 $(".box").animate({width: "toggle"});

Sin embargo, parece que no puedo combinar los dos anteriores. Estos dos intentos fallaron -

 // ($(".box").css('display') == 'block').animate({width: "toggle"}); // ($(".box").css('display') == 'block').animate({width: "toggle"}); var datebox = ($(".box").css('display') == 'block') datebox.animate({width: "toggle"}) datebox.animate({width: "toggle"})

Actualización 1

Intenté la sugerencia de Cucunber y obtuve este error: Uncaught TypeError: ".box".each no es una función

ingrese la descripción de la imagen aquí

Actualización 2

Resolví el problema resaltado en la Actualización 1 agregando $ a ('.box') , Cucunber actualizó su respuesta a continuación en función del problema que enfrenté.

Actualización 3

Jugué con la solución de Cucunber y eventualmente resolví mi problema con este código.

 $(".box" ).each(function( index ) { if ($(this).css('display') == 'block' ) { console.log( index + ": " + $( this ) ); } })
almost 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

La oración '$('.box').css('display') == 'block' devuelve una declaración booleana. Si lo sabe, el método .animate debe usarse con el elemento html (selector). Intenta usar algo como esto:

 '$('.box').css('display') == 'block' && $('.box').animate({width: 'toggle'})

combínelo con '.each()' y el resultado final será:

 $('.box').each(function(){ $(this).css('display') == 'block' && $(this).animate({width: 'toggle'}) })
almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error