3

ブラウザのサイズに応じて機能を追加する次のコードがありますが、ブラウザのサイズが変更された場合にこのプラグインの効果を削除するにはどうすればよいですか? (現在、ページがサイズ変更された場合ではなく、特定のサイズで読み込まれた場合にのみ機能します)

$(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??
      }
   });
}); 
4

2 に答える 2

0

DIV私は通常、プラグインを使用して特定の 内にスクリプトを作成するIDので、クリアしたい場合は を削除するだけIDで、SCRIPTが一緒に実行されます。

あなたの場合..

$(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... ウィンドウ サイズに基づいて、レスポンシブ CSS ファイルを含めます。

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

それが役立つことを願っています、幸運を祈ります

于 2013-04-08T11:30:41.530 に答える