javascript - 仅在特定宽度的窗口上调用 jQuery 函数
问题描述
我在我的网站上使用此代码。我只想在特定宽度的窗口中加载此代码。例如,在小于 768 像素的情况下,将不再调用此脚本。
jQuery(document).ready(function() {
var owl = jQuery('.owl-carousel');
owl.owlCarousel({
rtl: true,
margin: 10,
nav: true,
loop: true,
responsive: {
0: {
items: 1
},
600: {
items: 3
},
1000: {
items: 5
}
}
})
})
解决方案
您可以使用 jQuery 的宽度函数,然后执行以下操作:
jQuery(document).ready(function() {
if (jQuery( window ).width() > 768) {
/// your code here
}
});
推荐阅读
- java - Hibernate loader 在 System.identityHashCode 中花费大量时间
- python - 为什么TypedDict调用update方法时mypy不通过
- javascript - MongoDB 聚合:我想从电影中提取最昂贵的流派,我可以计算出那个流派,但我无法提取它的标题
- pointers - 为什么指针在 64 位计算机上是两倍大?
- c# - TCP/Server 我可以从另一个类调用Form1的组件
- gcc - 无法在 Ubuntu 20.04 上安装 Linux 内核
- entity-framework-core - 如何禁用可选的依赖实体
- plot - 产生正弦信号和相位差
- c# - 在转发器链中遇到循环依赖?
- c++ - 如何创建一个算法来找到所有可能的配对(参考中国邮递员问题)?