Using a function
Hey wasn't sure how to explain or ask this question so I'll demonstrate with code, say I have this:
$(function() {
$(window).resize(foo());
function foo() {
alert('bar');
}
});
How do I make that work inst开发者_JAVA百科ead of doing this:
$(window).resize(function() {
foo();
});
$(function() {
$(window).resize(foo);
});
function foo() {
alert('bar');
}
You basically need to pass the function pointer to jquery.. when you do function(){foo();}
you are creating an anonymous function.
Live Demo
精彩评论