JavaScript Start fixed position in determinated position

I have this code in Javascript:

var  menuPosition = $('.scroll-nav').offset().top;
var  menuPos = 110;

if (menuPosition = menuPos) {
  $('.scroll-nav').addClass('stick-menu');
  $('.fake-nav').removeClass('stick-menu');
}

My idea is when the position of the menuPostion be in 110px stick the .scroll-nav... but when I load the page the code is executed automaticaly.

Any idea?

EDIT

Solution to my question:

var distance = $('.scroll-nav').offset().top + 200, //+200 BECAUSE JQUERY OFFSET DONT GET MARGINS AND PADDINGS (+200 is an estimative of my total)
$window = $(window);

$window.scroll(function() {
    if ( $window.scrollTop() >= distance ) {
        $('.scroll-nav').addClass('is-sticky');
        $('.fake-nav').removeClass('is-sticky');
    }
    if ( $window.scrollTop() <= distance ) {
        $('.scroll-nav').removeClass('is-sticky');
        $('.fake-nav').addClass('is-sticky');
    }
});
Answer:1

Wrap this into a function and add event listener on scroll which would fire it when scrolled.

Answer:2

I'm making a Simon game, where there are 4 quarter circles all with class name 'colorButton': red, yellow blue and green. I'd like it so that when it's the computer turn, all pointer events to the 4 ...

I'm making a Simon game, where there are 4 quarter circles all with class name 'colorButton': red, yellow blue and green. I'd like it so that when it's the computer turn, all pointer events to the 4 ...

  1. canvas
  2. canada
  3. cancelled
  4. canceled vs cancelled
  5. canada goose
  6. cancun flights
  7. cane corso
  8. canes
  9. canadian prime minister
  10. canker sore
  11. candy
  12. cancer
  13. cancun
  14. canon
  15. canvas prints
  16. cancer sign
  17. candace owens
  18. canada news
  19. candytopia
  20. canlis

var a = 2; var b = a; console.log( b ); //2 a= 5; console.log( b ); //2 Q: Why variable 'b' is getting value 2 even when variable 'a' is assigned a different value

var a = 2; var b = a; console.log( b ); //2 a= 5; console.log( b ); //2 Q: Why variable 'b' is getting value 2 even when variable 'a' is assigned a different value

I'm creating React application that use JsSIP library to answer calls made via VoIP SIP provider. I've already created a page that have two buttons (Accept and Reject). It successfully register SIP ...

I'm creating React application that use JsSIP library to answer calls made via VoIP SIP provider. I've already created a page that have two buttons (Accept and Reject). It successfully register SIP ...

I'm trying to use the arr.includes(item). The function should return True if the item is an element of the array. But it doesn't seem to be able to do so with a multidimensional array. Take a look at ...

I'm trying to use the arr.includes(item). The function should return True if the item is an element of the array. But it doesn't seem to be able to do so with a multidimensional array. Take a look at ...