jQuery:根据浏览器窗口大小禁用和启用插件?

标签 jquery responsive-design

我有以下代码来根据浏览器大小添加功能,但是如果调整浏览器大小,如何消除此插件的影响? (目前,仅当页面以特定尺寸加载时才有效,如果调整大小则无效)

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

最佳答案

我通常使用插件在具有特定IDDIV内创建脚本,所以当我想要清除时,只需删除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
      }
   });
}); 

或/并且...根据窗口大小包含响应式 CSS 文件。

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

希望对你有帮助,祝你好运

关于jQuery:根据浏览器窗口大小禁用和启用插件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15877286/

相关文章:

javascript - Jquery选择器无法识别

javascript - 使用 jQuery 获取查询集合中除第一个元素之外的所有元素的方法是什么。

jquery - 使用 iscroll 与 jquery 移动绑定(bind)问题

javascript - 如何防止页面逐渐显示?

css - Zurb Foundation 顶部栏下拉菜单在小屏幕上消失

wordpress - 如何在 $.ajax 函数中使用 backstretch 插件方法

javascript - 如何使用 JavaScript API 在移动设备的 map 中禁用两指缩放选项?

javascript - 将最后滚动的标题粘贴到视口(viewport)的顶部?

html - 在响应式设计中将元素居中

html - 无法在手机上滚动