我有以下代码来根据浏览器大小添加功能,但是如果调整浏览器大小,如何消除此插件的影响? (目前,仅当页面以特定尺寸加载时才有效,如果调整大小则无效)
$(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??
}
});
});
最佳答案
我通常使用插件在具有特定ID
的DIV
内创建脚本,所以当我想要清除时,只需删除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/