Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$(window).load OR $(window).scroll in the same function?

I have implemented stickyfloat (http://plugins.jquery.com/files/stickyfloat_0.htm) on a site. It works great with one gotcha. The function triggers on $(window).scroll and not on $(window).load. I want it to trigger on either because I am linking to anchor points in the page (http://tre-stage.wdogsystems.com:8000/faq/#does-the-sale-of-my-receivables-have-a-negative-effect-on-my-credit-report) and I would like the side menu to appear when the page loads and not just when I initiate a scroll.

If you look at the page above, it's working just as I want it to. However, this is only because I've repeated the same function with a $(window).load. This seems highly inefficient to me. So, is there a way to chain the two together?

For example:

$(window).scroll || $(window).load (function () ...
like image 318
Vaughn D. Taylor Avatar asked Feb 25 '23 06:02

Vaughn D. Taylor


1 Answers

jQuery's .bind()help method allows multiple events bound at once.

$(window).bind('scroll load', function() {
    // code here triggers for both, scroll & load events
});
like image 163
jAndy Avatar answered Mar 06 '23 16:03

jAndy