There is a function code that works with the width and scroll level $ (window). It is necessary to call this function either at the moment of scrolling the page, or at the moment of resizing the window.

Tell me, please, how to combine these two events?

Other words need to combine:

$(window).scroll(function(){ /* код функции */ }); $(window).resize(function(){ /* тот же код функции */ }); 

UPD: Solution

Right:

 var func = function(e){ /* resize and scroll logic */}; $(window).scroll(func).resize(func); 

Not properly:

 $(window).scroll(function() { func() }); $(window).resize(function() { func() }); 
  • In the same way, the option comes to register the function separately and in the cases of scroll and resize call it by its identifier. - Cypher
  • No, that's right, thanks :). Pretty elegant! :) I got to this option: $(window).scroll(function() { func() }); $(window).resize(function() { func() }); - Cypher
  • @Cypher, mark @Spectre's answer as correct, and leave yours as an example of how not to do it)) - Deonis
  • Are you talking about the code itself or about formatting a comment? :) PS finally found the comment conversion button in response. Next time I can do it myself :). Thank you) - Cypher

1 answer 1

I do not understand what's so complicated:

 var func = function(e){ /* resize and scroll logic */}; $(window).scroll(func).resize(func); 

or is the problem deeper?