Is there a shorter way in JavaScript to trigger a function before and on resize? -
here example of mean.
function x() { return ($(window).width() < 768) ? $('body').addclass('z') : $('body').removeclass('z') } function y() { x() $(window).on('resize', function() { x() }) }
if don't invoke function before attached window resize event can manually invoke resize during attachment:
$(window).on('resize', x).trigger('resize'); but downside of approach not fire x function create fake resize event (it can problematic in scenarios).
Comments
Post a Comment