gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 01:48:30 27 4
gpt4 key购买 nike

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

$(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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com