Using the resize event with modernizr.mq
in Using jQuery
•
10 years ago
I'm trying to activate a resize event on the following function:
$(function() { if (Modernizr.mq('only screen and (min-width: 1140px)')) { $('div#ss1').html('<div>[snip]</div>'); $('div#ss1').append('<div><gcse:searchbox-only></gcse:searchbox-only></div>'); } if (Modernizr.mq('only screen and (max-width: 1139px)')) { $('div#ss2').html('<div>[snip]</div>'); $('div#ss2').append('<div><gcse:searchbox-only></gcse:searchbox-only></div>'); } });
I wanted to add a resize listener to it. Based on http://api.jquery.com/resize/ I changed the first line to $(window).resize(function()
but then the whole function stopped working.
What am I doing wrong? I also found a post by Paul Irish and added smartresize to my plugins.js. I changed the function call from $(function()
to $(window).smartresize(function()
and again, my Modernizr calls stopped working. Changing it back to $(function()
and it worked again. Why can't I add a resize event listener of any type to this sucker? I was Googling yesterday and reading something about functions having to be defined in the same scope (I think I'm remembering that right).
1