是否可以防止鼠标悬停时Bootstrap轮播暂停并继续自动循环?

时间:2022-01-27 08:45:48

Is it possible to prevent the Bootstrap carousel pause on mouse hover behaviour and continue automatically cycling through the items instead?

是否可以阻止Bootstrap轮播暂停鼠标悬停行为并继续自动循环浏览项目?

The documentation only mentions the default behaviour of pause: "hover", if I change the pause argument to anything else then the carousel stops working altogether so I'm not sure how to disable this default behaviour.

文档仅提到暂停的默认行为:“hover”,如果我将pause参数更改为其他任何内容,则轮播将完全停止工作,因此我不确定如何禁用此默认行为。

5 个解决方案

#1


75  

I've found that a value of "false" will cause the carousel to keep cycling during a mouseover:

我发现值为“false”会导致轮播在鼠标悬停期间继续循环:

$('.carousel').carousel({
    pause: "false"
});

I am using Twitter Bootstrap v2.0.2

我正在使用Twitter Bootstrap v2.0.2

#2


40  

You can add this to the div .carousel too instead of using javascript.

你也可以将它添加到div .carousel而不是使用javascript。

Add delay time:

添加延迟时间:

data-interval="3000"

数据间隔=“3000”

Add if it pauses on hover or not, options are true and false

添加如果在悬停时暂停,则选项为true和false

data-pause="false"

数据暂停=“假”

Example would be:

示例是:

<div id="carousel" class="carousel" data-ride="carousel" data-interval="3000" data-pause="false">

This worked for me.

这对我有用。

#3


6  

$('.carousel').carousel({
        pause: 'none'
    })

for Bootstrap v3.3.4

for Bootstrap v3.3.4

#4


2  

Bootstrap 4 Remove Pause on hover

Bootstrap 4在悬停时删除暂停

$('.carousel').carousel({
    interval: 2000,
    cycle: true,
    pause: "null"
})

#5


0  

I have found that there are 2 things on which this cycling and pausing depends.

我发现骑自行车和暂停取决于两件事。

  1. When mouse enters (mouseenter - pause sliding)
  2. 鼠标进入时(mouseenter - 暂停滑动)
  3. When mouse leaves (mouseleave - resume sliding)
  4. 鼠标离开时(mouseleave - 恢复滑动)

Just change following line of code in your js/bootstrap.js file to allow continuous sliding.

只需更改js / bootstrap.js文件中的以下代码行以允许连续滑动。

.on('mouseenter', $.proxy(this.pause, this)) to

.on('mouseenter',$ .proxy(this.pause,this))来

.on('mouseenter', $.proxy(this.**cycle**, this))

.on('mouseenter',$ .proxy(this。** cycle **,this))

#1


75  

I've found that a value of "false" will cause the carousel to keep cycling during a mouseover:

我发现值为“false”会导致轮播在鼠标悬停期间继续循环:

$('.carousel').carousel({
    pause: "false"
});

I am using Twitter Bootstrap v2.0.2

我正在使用Twitter Bootstrap v2.0.2

#2


40  

You can add this to the div .carousel too instead of using javascript.

你也可以将它添加到div .carousel而不是使用javascript。

Add delay time:

添加延迟时间:

data-interval="3000"

数据间隔=“3000”

Add if it pauses on hover or not, options are true and false

添加如果在悬停时暂停,则选项为true和false

data-pause="false"

数据暂停=“假”

Example would be:

示例是:

<div id="carousel" class="carousel" data-ride="carousel" data-interval="3000" data-pause="false">

This worked for me.

这对我有用。

#3


6  

$('.carousel').carousel({
        pause: 'none'
    })

for Bootstrap v3.3.4

for Bootstrap v3.3.4

#4


2  

Bootstrap 4 Remove Pause on hover

Bootstrap 4在悬停时删除暂停

$('.carousel').carousel({
    interval: 2000,
    cycle: true,
    pause: "null"
})

#5


0  

I have found that there are 2 things on which this cycling and pausing depends.

我发现骑自行车和暂停取决于两件事。

  1. When mouse enters (mouseenter - pause sliding)
  2. 鼠标进入时(mouseenter - 暂停滑动)
  3. When mouse leaves (mouseleave - resume sliding)
  4. 鼠标离开时(mouseleave - 恢复滑动)

Just change following line of code in your js/bootstrap.js file to allow continuous sliding.

只需更改js / bootstrap.js文件中的以下代码行以允许连续滑动。

.on('mouseenter', $.proxy(this.pause, this)) to

.on('mouseenter',$ .proxy(this.pause,this))来

.on('mouseenter', $.proxy(this.**cycle**, this))

.on('mouseenter',$ .proxy(this。** cycle **,this))