These two functions should be fired on load and on resize. I'm wondering how to write it more compact and beautiful. Any ideas?
$(document).ready(function() {
fullScreen();
footer();
$(window).resize(function() {
fullScreen();
footer();
});
});
You can trigger the resize event right after you register your handler:
$(document).ready(function() {
$(window).resize(function() { // Register handler.
fullScreen();
footer();
}).resize(); // Trigger event.
});
Well, you could combine them into one function, but I'm not sure it's more "beautiful":
jQuery(function($) {
both();
$(window).resize(both);
function both() {
fullScreen();
footer();
}
});
It does address the issue of not repeating yourself.
Off-topic: I also switched $(document).ready(function(){...
to jQuery(function($){...
. It does the same thing, but makes the quoted code compatible with noConflict
, if that's useful. If you'll never want noConflict
compatibility, you can use $(function(){...
instead, but hey, for six extra chars...
$(function() {
function both() {
fullScreen();
footer();
}
both();
$(window).resize(both);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With