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

140
Views
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 answers
Answer question

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 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!