69 posts
  • Exclusive Author
  • France
  • Has been a member for 2-3 years
rafaelrasalan says

Hi, i’m working on a simple responsive page with superfish implemented in navigation, i want to disable the plugin when the window is resized to 768px and below because the navigation will be replaced by a toggle nav, so i’m trying to remove the .sf-menu class with jQuery but it doesn’t work.

Here’s my code:
function checkWidth(init)
{
if ($(window).width() < 768) {
     $('ul').removeClass('.sf-menu');
   }
    else {
        if (init == false) {
            $('ul').addClass('.sf-menu');
        }
    }
}
$(document).ready(function() {
    checkWidth(true);
    $(window).resize(function() {
        checkWidth(false);
    });
});

Any help would be appreciated.

315 posts
  • Sold between 50 000 and 100 000 dollars
  • Most Wanted Bounty Winner
  • Envato Studio (Microlancer) Beta Tester
  • Europe
  • Referred between 100 and 199 users
  • Bought between 10 and 49 items
  • Has been a member for 2-3 years
  • Exclusive Author
SuggeElson says

It`s hard to help you if i not see the html

2441 posts
  • Has been a member for 5-6 years
  • Exclusive Author
  • Europe
  • Bought between 10 and 49 items
  • Referred between 100 and 199 users
  • Sold between 100 and 1 000 dollars
  • Envato Studio (Microlancer) Beta Tester
digitalimpact says

Try with $('body').innerWidth();

269 posts
  • Elite Author
  • Europe
  • Has been a member for 3-4 years
  • Referred between 200 and 499 users
  • Bought between 10 and 49 items
  • Exclusive Author
  • Envato Studio (Microlancer) Beta Tester
+1 more
Kopyov says
try this
    $('body').resize(function () {
      var width = $(this).width();
        if (width < 769) {
            //do stuff
        }
        else { // do stuff }
    }).resize();
2024 posts
  • Elite Author
  • Author had a Free File of the Month
  • Has been a member for 4-5 years
  • Austria
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Envato Studio (Microlancer) Beta Tester
+3 more
revaxarts says

always listen to the window object when resizing:

$(window).resize(function(){
   //do stuff here
});
116 posts YeahThemes
  • Exclusive Author
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Has been a member for 3-4 years
  • Bought between 1 and 9 items
  • Referred between 100 and 199 users
Manh says

Try this:


function your_function_name(){

    var windowWidth = jQuery(window).width();

    if(windowWidth <= 768) {
        jQuery('ul').removeClass('.sf-menu');
    }else{

        jQuery('ul').addClass('.sf-menu');
    }

}

jQuery(document).ready(function($){

    your_function_name();

    jQuery(window).bind("resize",function(){
        your_function_name();
    });

}
1034 posts
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Sold between 100 and 1 000 dollars
  • Bought between 1 and 9 items
  • United Kingdom
  • Has been a member for 2-3 years
BenSheppard says

always listen to the window object when resizing:
$(window).resize(function(){
   //do stuff here
});

+1 what I was going to say :)

by
by
by
by
by
by