Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

138
Vistas
How do I trigger multiple events simultaneously in JavaScript/CSS?

I have a sticky navbar working using HTML/CSS/JavaScript. When the navbar sticks when scrolling down, I want two animations to occur; one for text, one for an image.

The two sections of JavaScript that I've included below for the animations both work individually but I can't work out how to get them to both working simultaneously.

Please let me know if any more information is required and thanks in advance.

Javascript:

/*Sticky navbar*/
var height = $('#header').height();

$(window).scroll(function () {
  if($(this).scrollTop() > height){
    $('.navbar').addClass('fixed');
  }else{
    $('.navbar').removeClass('sticky');
  }
});


/*Animates a text logo*/
$(document).ready(function(){
  head = $(".navlogo");

  $(document).scroll(function(){
      var top = $(this).scrollTop();
    if(top>5){
      head.addClass('navlogoActive');
    }
    else{
      head.removeClass('navlogoActive');
      head.addClass('navlogo');
    }
  });
});


/*Animates an image*/
$(document).ready(function(){
  head = $(".mascotzoom");

  $(document).scroll(function(){
      var top = $(this).scrollTop();
    if(top>5){
      head.addClass('mascotzoomActive');
    }
    else{
      head.removeClass('mascotzoomActive');
      head.addClass('mascotzoom');
    }
  });
});

CSS:

/*Text logo*/
.navlogo{
  float: left; 
  color: #fff;
  transition:all .2s linear;
  transform:translateX(-150%);
}

.navlogoActive{
  transform:translateX(0%);
}


/*Image logo*/
.mascotzoom {
  position: relative;
  display: block;
  width: 110px;
  height: 110px;
  transition: all, 0.5s;
}
.mascotzoomActive {
  transform: scale(0%);
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Through further trial and error, I was able to fix the issue in the JavaScript as I hoped to and got both animations working together.

Posting the fix below. Cheers to anyone reading this.

/*Sticky navbar*/
var height = $('#header').height();

$(window).scroll(function () {
  if($(this).scrollTop() > height){
    $('.navbar').addClass('fixed');
  }else{
    $('.navbar').removeClass('sticky');
  }
});


/*Animates a text logo and image logo*/
$(document).ready(function(){
  head = $(".navlogo");

  $(document).scroll(function(){
      var top = $(this).scrollTop();
    if(top>5){
      head.addClass('navlogoActive');
        $('.mascotzoom').addClass('mascotzoomActive')({
        });
    }
    else{
      head.removeClass('navlogoActive');
      head.addClass('navlogo');
        $('.mascotzoom').removeClass('mascotzoomActive')({
        });
    }
  });
});

about 4 years ago · Juan Pablo Isaza 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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda