Hello, friends!
JQuery has two event handlers for the window: resizing the screen (resize) and scrolling. How to make the event (in the particular case - the assignment of a variable to the height of the block with id) processed by any of the actions? I understand that you can just write the code twice, but I think there is some more beautiful solution?

$(window).resize(function() { nav_height = $('#stick_menu').height(); }); $(window).scroll(function() { nav_height = $('#stick_menu').height(); }); 

    1 answer 1

    The on method allows you to specify multiple events separated by spaces in the first parameter.

    For example:

     $(window).on('scroll resize', function() { nav_height = $('#stick_menu').height(); }); 
    • Need to deal with the basics))) thanks a lot! - Igor Voinov
    • @ IgorVoynov On this site, instead of thanks, there is a check mark under the answer rating for accepting an answer as useful (or correct) - tutankhamun