• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

97
Vistas
call a function when slideDown or slideUp effect has finished

I have a simple dropdown list, I want when the user toggles the dropdown list to show or hide another div using the jquery method slideToggle, unfortunately, I am struggling to solve the problem.

Expected: when the user clicks an icon it should show the list and hide another div (slideDown effect) when the user clicks again for closing the dropdown list (slideUp effect), I want to show the hidden div.

 var link = $('.sprzatanie-link');

  link.click(function(e) {
    e.preventDefault();
    list.slideToggle("fast", function(){
      console.log('do something')
      if("slideDown"){
        $('.dezynfekcja-dropdown').hide();
      }else if("slideUP"){
        $('.dezynfekcja-dropdown').show();
      }
    });
  });

I tried adding a callback function but I don't know how to check the slide effect if it's slideDown or slideUp.

Any idea will be appreciated.

almost 3 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Once toggle finishes it basically hides or shows the element being toggled. So in the complete callback you can simply check if your element is shown or hidden.

 var link = $('.sprzatanie-link');

  link.click(function(e) {
    e.preventDefault();
    list.slideToggle("fast", function(){
      // `this` refers to the DOM element being toggled.
      // We can use `is(":visible")` to check if it visible or not
      let isVisible = $(this).is(":visible");

      // show console message that tells us if element is hidden or visible
      console.log(this.innerText, ' is now ', isVisible);

      // use isVisible to do whatever you want show/hide etc
      if(isVisible) {
        $('.dezynfekcja-dropdown').hide();
      } else {
        $('.dezynfekcja-dropdown').show();
      }
    });
  });
almost 3 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda