Eric ERK Eric ERK - 1 year ago 86
Javascript Question

How to Disable / Re-enable Javascript on window resize?

I need to be able to disable / re-enable Javascript on window resize?
Currently when the window is resized on the desktop, the nav bar sticks and is the only thing visible instead of the content.

if ( $(window).width() <= 1200 ) {

$('nav').addClass('original').clone().insertAfter('nav').addClass('cloned').css('position','fixed').css('top','0').css('margin- top','0').css('z-index','500').removeClass('original').hide();

scrollIntervalID = setInterval(stickIt, 10);

function stickIt() {

var orgElementPos = $('.original').offset();
orgElementTop =;

if ($(window).scrollTop() >= (orgElementTop)) {

as original element.
orgElement = $('.original');
coordsOrgElement = orgElement.offset();
leftOrgElement = coordsOrgElement.left;
widthOrgElement = orgElement.css('width');
} else {

Answer Source

You can bind an event handler to the "resize" JavaScript event:

$(window).resize(function() {

    if($(window).width() <= 1200) {
        //You code here
    }else {
        //You code here


Your code will be executed whenever the browser window's size is changed.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download