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

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -