Eric ERK
Eric ERK

Reputation: 369

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.

<script>  
if ( $(window).width() <= 1200 ) {
}else{


$('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 = orgElementPos.top;               

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

as original element.     
orgElement = $('.original');
coordsOrgElement = orgElement.offset();
leftOrgElement = coordsOrgElement.left;  
widthOrgElement = orgElement.css('width');
   th',widthOrgElement).show();
$('.original').css('visibility','hidden');
} else {
$('.cloned').hide();
$('.original').css('visibility','visible');
}
}
</script>

Upvotes: 0

Views: 1214

Answers (3)

caldera.sac
caldera.sac

Reputation: 5088

you can do it by checking the window width

var winWidth = $(window).width(); // you can get the window width from this

//Then check with the condtion(compare with your need ex :)



  if(winWidth <= 600)
   {
     //your work here
     alert("window resize less than or equal to 600");
   }
   else
   {
     //your work here
     alert("window resize greater than to 600");
   }

Upvotes: 1

Kld
Kld

Reputation: 7068

    $(window).resize(function() {        
        if($(window).width() <= 1200) {
            //small screen code
        }else {
            //large screen code            }

    });

   //trigger window resize event on load
   $(window).trigger('resize');

Upvotes: 1

Ismail RBOUH
Ismail RBOUH

Reputation: 10450

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.

Upvotes: 1

Related Questions