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

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -