如何在移动设备中停止引导程序转盘自动滑动
How to stop bootstrap carousel automatic slide in mobile
嗨,我正试图找到一种方法来停止bootstraps转盘自动滑动功能,使其仅在移动设备中停止。我试着用javascript实现这一点,但我使用的代码似乎不起作用。
var ismobile = window.matchMedia("only screen and (max-width: 760px)");
if (ismobile.matches) {
$('.carousel').carousel ({
interval:false
});
}
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
$('.carousel').carousel ({
interval:false
});
}
从这里得到
我正在使用这个,为我工作的格栅:
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
$('.carousel').carousel ({
interval: isMobile.any() ? false : 5000
});
来源:http://www.abeautifulsite.net/detecting-mobile-devices-with-javascript/
轻微的更新,因为我也遇到了一些小麻烦——上面的代码片段并没有完全起作用。
(function(){
var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
var windowIsThin = window.matchMedia("(max-width:992px)").matches;
if (isMobile || windowIsThin) {
//carousel disabled
$('.carousel').carousel({
interval: false
});
};
});
在chrome、IE、Firefox和Opera中进行了测试。
我收到一个错误"不是函数"(使用bootstrap 5和webpack)。
所以最后只需:
var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
var windowIsThin = window.matchMedia("(max-width:992px)").matches;
if (isMobile || windowIsThin) {
$('.carousel').attr("data-bs-interval", "false");
};
(使用上面的答案)
相关文章:
- Html引导程序警报自动关闭困难
- 引导程序:在导航栏中,显示悬停在单个位置的基于Li Link的不同内容
- Twitter引导程序Typeahead-Id&标签
- 引导程序崩溃一次只能看到一个
- 引导程序/基础堆叠行/列
- 如何保持引导程序下拉复选框列表下拉
- Angular UI&引导程序:点击链接时折叠移动导航栏
- 仅在移动设备上使用angular ui引导程序转盘
- 折叠导航按钮不适用于twitter引导程序设计的移动设备
- 使用引导程序对移动设备的列重新排序
- 在移动设备上的引导程序 3 自动调整大小(高度)中禁用轮播
- 更改引导程序 2.1.1 工具提示在移动设备上的位置
- 移动设备中的引导程序JavaScript问题
- 移动和chrome上的引导程序下拉菜单问题
- 在移动设备上单击链接之前引导程序下拉菜单崩溃
- 更改引导程序后的移动菜单切换错误'的移动导航断点
- 如何在移动设备中停止引导程序转盘自动滑动
- 引导程序 3 日期选取器 v4:移动鼠标时自动选择自定义周
- 引导程序下拉菜单四处移动,样式不显示
- 引导程序不显示 iframe 内的移动布局