3

I've got the following code to add a function depending on browser size, but how do I remove the effects of this plugin if the browser is resized? (Currently it only works if the page is loaded at the specific size, not if it's resized)

$(document).ready(function(){
   $(window).resize(function() {
      if ($(window).width() >= 420) {
          // Enable the plugin to make the tab functionality...
          $( "#tabs" ).tabs();
      }
      else {
        // Code needed to completely disable the tab functionality??
      }
   });
}); 

2 Answers 2

0

I normaly create the script with the plug-in, inside a DIV with specific ID, so when I wan to to clear, just remove the ID and the SCRIPT will go with him.

In your case..

$(document).ready(function(){
   $(window).resize(function() {
      if ($(window).width() >= 420) {
          // Enable the plugin to make the tab functionality...
          var tempScript = '<div id="newTempId"><script type="text/javascript" src="../js/plugInScript.js"></script></div>';
          $('body').append(tempScript); // append the DIV with the PlugIn script inside
          $( "#tabs" ).tabs();
      }
      else {
        // Code needed to completely disable the tab functionality??
        $( "#tabs" ).tabs({ disabled: [ 0, 2 ] }); // see API info at http://api.jqueryui.com/tabs/#option-disabled
        $('newTempId').remove(); // Remove the DIV that include the script
      }
   });
}); 

OR/And... include a responsive CSS file, based on the window size.

<link href="../css/responsive_style.css" rel="stylesheet" type="text/css" media="screen and (min-width:419px)" />

Hope it helps, Good Luck

Sign up to request clarification or add additional context in comments.

2 Comments

Hi, So with your solution, does this hide the tabbed content or simply just remove the script? - As I still need the content displayed when the script is removed.
Will remove everything inside #newTempId div from the DOM, in my example, only the script and his functionality. (Unless you put/move the tabbed content inside it). If you want to give us a working example, we can try to adjust for your needs.
0

If you're using the jQuery UI tabs plugin (I guess so):

var $win = $(window),
    $tabs = $( "#tabs" );

$win.resize(function() {
  if ($win.width() >= 420 && !$tabs.is('.tabbed') {
      // Enable the plugin to make the tab functionality...
      $tabs.tabs().addClass('tabbed').removeClass('destroyed');
  } else if(!$tabs.is('.destroyed')) {
      // remove plugin functionality and add class
      // so we don't try to execute this on every resize
      $tabs.tabs('destroy').addClass('destroyed').removeClass('tabbed');
  }
});

2 Comments

Hi, - I'm not using jQuery UI i'm afraid :( - I don't suppose you have a generic solution out of interest? Let me know if you need anything from me :) - I'm actually using this - os.alfajango.com/easytabs
But doesn't this plugin init with .easytabs() not .tabs()? Couldn't find any demo on easytabs' page which calls .tabs()...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.