Javascript 如何在移动设备中停止引导转盘自动滑动

Javascript 如何在移动设备中停止引导转盘自动滑动,javascript,css,twitter-bootstrap,carousel,Javascript,Css,Twitter Bootstrap,Carousel,嗨,我正在试图找到一种方法来停止引导转盘自动滑动功能,以停止只有在移动。我试图自己用javascript实现这一点,但我使用的代码似乎不起作用 var ismobile = window.matchMedia("only screen and (max-width: 760px)"); if (ismobile.matches) { $('.carousel').carousel ({ interval:false });

嗨,我正在试图找到一种方法来停止引导转盘自动滑动功能,以停止只有在移动。我试图自己用javascript实现这一点,但我使用的代码似乎不起作用

var ismobile = window.matchMedia("only screen and (max-width: 760px)");

    if (ismobile.matches) {
        $('.carousel').carousel ({
            interval:false
        });
    }


轻微更新中获得,因为我在这方面也遇到了一些问题,上面的代码片段不太有效

(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中进行了测试。

轻微更新,因为我在这方面也遇到了一些问题,上面的代码片段并不太有效

(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中测试。

我正在使用这一款,为我工作:

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

来源:

我正在使用这个,为我工作:

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

来源:

请不要使用“bootstrap”标签,使用“twitter bootstrap”因为它意味着其他东西。@DanielCheung这是一场徒劳的战斗
bootstrap
应该被烧掉或重新调整用途…@cvrebert我知道,但我认为当用户使用“bootstrap”时,我们应该提醒他们,而不是重新调整用途,因为它最终会像“字面上”这个词一样,在字典中被描述为“夸张的”,因为人们用错了它。我想我会用meta stackoverflow提问。请不要使用“bootstrap”标签,使用“twitter bootstrap”,因为它意味着其他东西。@DanielCheung这是一场徒劳的战斗
bootstrap
应该被烧掉或重新调整用途…@cvrebert我知道,但我认为当用户使用“bootstrap”时,我们应该提醒他们,而不是重新调整用途,因为它最终会像“字面上”这个词一样,在字典中被描述为“夸张的”,因为人们用错了它。我想我会在meta stackoverflow中询问。尝试将此与另一个设置台式机/笔记本电脑上的间隔速度的函数一起使用,即<代码>$('#myCarousel')。carousel({interval:3000})但设备脚本无法处理此问题。如果我删除它,设备脚本也会影响台式机/笔记本电脑。有什么想法吗?@SteveJoiner为此打开一个JSFIDLE,这样我们就可以看到了。试着将它与另一个函数一起使用,该函数设置桌面/笔记本电脑上的间隔速度,这就是<代码>$('#myCarousel')。carousel({interval:3000})但设备脚本无法处理此问题。如果我删除它,设备脚本也会影响台式机/笔记本电脑。有什么想法吗?@SteveJoiner打开一个JSFIDLE让我们看看。