jQuery:禁用&是否启用基于浏览器窗口大小的插件? [英] jQuery: Disable & Enable Plugin based on browser window size?
本文介绍了jQuery:禁用&是否启用基于浏览器窗口大小的插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码来添加功能,具体取决于浏览器的大小,但是如果调整了浏览器的大小,如何删除此插件的效果? (当前,只有在页面以特定大小加载时才有效,而在调整页面大小时则无效)
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??
}
});
});
推荐答案
如果您使用的是jQuery UI标签插件(我想是):
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');
}
});
这篇关于jQuery:禁用&是否启用基于浏览器窗口大小的插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文