70 posts
  • Has been part of the Envato Community for over 2 years
  • Sells items exclusively on Envato Market
  • Located in France
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.

320 posts
  • Has been part of the Envato Community for over 3 years
  • Sells items exclusively on Envato Market
  • Has sold $40,000+ on Envato Market
  • Won a Most Wanted contest
+4 more
SuggeElson says

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

2468 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $100+ on Envato Market
  • Has referred 100+ members
  • Has been a beta tester for an Envato feature
+2 more
digitalimpact says

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

283 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Made it to the Authors' Hall of Fame
  • Had an item featured on Envato Market
  • Sells items exclusively on Envato Market
+5 more
Kopyov says
try this
    $('body').resize(function () {
      var width = $(this).width();
        if (width < 769) {
            //do stuff
        }
        else { // do stuff }
    }).resize();
2191 posts
  • Located in Europe
  • Made it to the Authors' Hall of Fame
  • Had an item featured on Envato Market
  • Participated in a focus group or interview to improve the user experience on Envato Market
+10 more
revaxarts says

always listen to the window object when resizing:

$(window).resize(function(){
   //do stuff here
});
116 posts YeahThemes
  • Elite Author: Sold more than $75,000 on Envato Market
  • Sells items exclusively on Envato Market
  • Has sold $125,000+ on Envato Market
  • Has referred 100+ members
+2 more
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
  • Has sold $100+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
BenSheppard says

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

+1 what I was going to say :)

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by