Reputation: 2799
I want to trigger a function that only trigger on scroll, is that possible?
$(document).ready(function()
$(document).scroll(function() {
// do something here
});
// here I want to trigger the scroll function (without scrolling)
});
I tried $(document).scroll();
without success:
$(document).ready(function()
$(document).scroll(function() {
// do something here
});
$(document).scroll();
});
Upvotes: 0
Views: 533
Reputation: 67898
Change it to use a named function:
$(document).ready(function()
$(document).scroll(onScroll);
onScroll();
});
function onScroll() {
}
Now that the function is named you can freely execute that code whenever you want.
Upvotes: 2