admin管理员组文章数量:1429124
Has anybody ever run into Bootstrap's carousel not resetting on page load. It seems to be acting weird in Safari on both the desktop and iPads.
On desktops, the slide/tab you leave on is still active if you press the back button and return to the previous page.
On iPads, the slide/tab you leave on is no longer marked as active when you press the back button to return. This is really the larger problem here.
Is there a way to force data-slide-to='1'
to always be active on page load.
$('.carousel.graph').carousel({
pause: true,
interval: false
});
$(window).on('load', function () {
var initial = $('table.picker td').attr('data-slide-to', 0);
initial.addClass('active');
});
This did not work.
EDIT
Here's my HTML as well...
<div id="carousel" class="carousel slide graph" data-ride="carousel">
<table class="carousel-indicators picker">
<tr>
<td class="active" data-target="#carousel" data-slide-to="0">
<div><span>Slide 1</span></div>
</td>
<td class="" data-target="#carousel" data-slide-to="1">
<div><span>Slide 2</span></div>
</td>
<td class="blank"></td>
</tr>
<tr>
<td class="" data-target="#carousel" data-slide-to="2">
<div><span>Slide 3</span></div>
</td>
<td class="" data-target="#carousel" data-slide-to="3">
<div><span>Slide 4</span></div>
</td>
<td class="" data-target="#carousel" data-slide-to="4">
<div><span>Slide 5</span></div>
</td>
</tr>
</table>
<!-- Wrapper for slides -->
<div class="carousel-inner graph">
<div class="item active">
<img src="/img/1.jpg" alt="" class="img-responsive" />
</div>
<div class="item">
<img src="/img/2.jpg" alt="" class="img-responsive" />
</div>
<div class="item">
<img src="/img/3.jpg" alt="" class="img-responsive" />
</div>
<div class="item">
<img src="/img/4.jpg" alt="" class="img-responsive" />
</div>
<div class="item">
<img src="/img/5.jpg" alt="" class="img-responsive" />
</div>
</div>
</div>
My problem is that active
is not being reapplied to the TD
with data-slide-to="0"
. I can tell because when a "picker TD" is active it has a different background color. When I press the back arrow on iPads, all the "picker TDs" have the same background color.
Has anybody ever run into Bootstrap's carousel not resetting on page load. It seems to be acting weird in Safari on both the desktop and iPads.
On desktops, the slide/tab you leave on is still active if you press the back button and return to the previous page.
On iPads, the slide/tab you leave on is no longer marked as active when you press the back button to return. This is really the larger problem here.
Is there a way to force data-slide-to='1'
to always be active on page load.
$('.carousel.graph').carousel({
pause: true,
interval: false
});
$(window).on('load', function () {
var initial = $('table.picker td').attr('data-slide-to', 0);
initial.addClass('active');
});
This did not work.
EDIT
Here's my HTML as well...
<div id="carousel" class="carousel slide graph" data-ride="carousel">
<table class="carousel-indicators picker">
<tr>
<td class="active" data-target="#carousel" data-slide-to="0">
<div><span>Slide 1</span></div>
</td>
<td class="" data-target="#carousel" data-slide-to="1">
<div><span>Slide 2</span></div>
</td>
<td class="blank"></td>
</tr>
<tr>
<td class="" data-target="#carousel" data-slide-to="2">
<div><span>Slide 3</span></div>
</td>
<td class="" data-target="#carousel" data-slide-to="3">
<div><span>Slide 4</span></div>
</td>
<td class="" data-target="#carousel" data-slide-to="4">
<div><span>Slide 5</span></div>
</td>
</tr>
</table>
<!-- Wrapper for slides -->
<div class="carousel-inner graph">
<div class="item active">
<img src="/img/1.jpg" alt="" class="img-responsive" />
</div>
<div class="item">
<img src="/img/2.jpg" alt="" class="img-responsive" />
</div>
<div class="item">
<img src="/img/3.jpg" alt="" class="img-responsive" />
</div>
<div class="item">
<img src="/img/4.jpg" alt="" class="img-responsive" />
</div>
<div class="item">
<img src="/img/5.jpg" alt="" class="img-responsive" />
</div>
</div>
</div>
My problem is that active
is not being reapplied to the TD
with data-slide-to="0"
. I can tell because when a "picker TD" is active it has a different background color. When I press the back arrow on iPads, all the "picker TDs" have the same background color.
1 Answer
Reset to default 4$('.carousel.graph').carousel({
pause: true,
interval: false
}).carousel(0);
.carousel(number)
Cycles the carousel to a particular frame (0 based, similar to an array).
Docs: http://getbootstrap./javascript/#carousel-usage
本文标签: javascriptReset Bootstrap 3 Carousel on page loadStack Overflow
版权声明:本文标题:javascript - Reset Bootstrap 3 Carousel on page load - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745448110a2658756.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论