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

'hasOwnProperty' in javascript -

python - ValueError: No axis named 1 for object type <class 'pandas.core.series.Series'> -

java - How to provide dependency injections in Eclipse RCP 3.x? -