简体   繁体   English

如何在手机中停止引导轮播自动滑动

[英]How to stop bootstrap carousel automatic slide in mobile

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. 我尝试使用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
 });
}

got from here 这里得到

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
});

Source: http://www.abeautifulsite.net/detecting-mobile-devices-with-javascript/ 资料来源: http : //www.abeautifulsite.net/detecting-mobile-devices-with-javascript/

Slight update as I too was having a little trouble with this the code snippet above taken as it is didn't quite work. 轻微的更新,因为上面的代码片段对我来说也有点麻烦,因为它不太起作用。

(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
        });
    }; 

});

Tested in chrome, IE, Firefox and Opera. 经过chrome,IE,Firefox和Opera的测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM