如何在手机中停止引导轮播自动滑动 [英] How to stop bootstrap carousel automatic slide in mobile
本文介绍了如何在手机中停止引导轮播自动滑动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试找到一种方法来停止引导带轮播自动滑动功能,使其仅在移动设备中停止。我尝试使用JavaScript自己执行此操作,但我使用的代码似乎无法正常工作。
Hi I'm trying to find a way to stop bootstraps carousel automatic slide function to stop only in mobile. I tried to carry this out myself using javascript, but the code I've used doesn't seem to work.
var ismobile = window.matchMedia("only screen and (max-width: 760px)");
if (ismobile.matches) {
$('.carousel').carousel ({
interval:false
});
}
推荐答案
我正在使用这个,为我工作的rate子:
I am using this one, working grate for me:
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/
这篇关于如何在手机中停止引导轮播自动滑动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文