gpt4 book ai didi

javascript - Bootstrap 轮播重置为默认设置

转载 作者:行者123 更新时间:2023-11-30 16:53:30 36 4
gpt4 key购买 nike

我一直在研究一个 Bootstrap 轮播,但还有一个主要问题。

暂停功能是必需的,它在使用时可以正常工作,但是当焦点从暂停按钮移开时,轮播将重置为默认设置并再次开始循环。

我已经尝试了另外两种方法来阻止这种行为,但都没有用;更改间隔而不是调用暂停并使暂停按钮设置一个标志,该标志将触发触发暂停的窗口的 setInterval

是否有更好的方法可以在按下暂停按钮时永久停止轮播循环?

该页面还使用了 adobe mega 菜单,我在其中包含了脚本,以防它们导致问题。

<html>
<head>

<link href="css/bootstrap-combined.min.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="js/jquery-accessibleMegaMenu.js"></script>
<script src="js/bootstrap.js"></script>
<script src="js/bootstrap-carousel.js"></script>

</head>

<body>
<div class="page-wrapper">
<!-- content starts here -->
<div class="content">
<center>
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
<li data-target="#myCarousel" data-slide-to="3"></li>
</ol>

<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="http://placehold.it/800x300" alt="EXCEL 2015">
</div>

<div class="item">
<img src="http://placehold.it/700x300" alt="EEO Programs">
</div>

<div class="item">
<img src="http://placehold.it/800x300" alt="Place hold">
</div>

<div class="item">
<img src="http://placehold.it/600x300" alt="Flower">
</div>
</div>

<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>

<!-- Play and Pause -->
<div id="carouselButtons">
<input type="button" class="btn start-slide" value="Play" id='playButton'>
<input type="button" class="btn pause-slide" value="Pause" id='pauseButton'>
</div>
</div>
</center>
</div>
</div>

<!-- Nav menu scripts -->
<script>
$("nav:first").accessibleMegaMenu({
/* prefix for generated unique id attributes, which are required
to indicate aria-owns, aria-controls and aria-labelledby */
uuidPrefix: "accessible-megamenu",

/* css class used to define the megamenu styling */
menuClass: "nav-menu",

/* css class for a top-level navigation item in the megamenu */
topNavItemClass: "nav-item",

/* css class for a megamenu panel */
panelClass: "sub-nav",

/* css class for a group of items within a megamenu panel */
panelGroupClass: "sub-nav-group",

/* css class for the hover state */
hoverClass: "hover",

/* css class for the focus state */
focusClass: "focus",

/* css class for the open state */
openClass: "open"
});
</script>
<!-- carousel scripts -->
<script>
$(document).ready(function() {
$('#myCarousel').carousel({
interval: 2000,
pause: "false"
});
});

$('#playButton').click(ClickOnPlayButton);

function ClickOnPlayButton(){
$('#myCarousel').carousel('cycle');
}

$('#pauseButton').click(ClickOnPauseButton);

function ClickOnPauseButton(){
$('#myCarousel').carousel('pause');
}
</script>
</body>
</html>

最佳答案

即使在鼠标悬停时也保持轮播循环(用户始终可以通过单击轮播中的导航按钮返回到特定幻灯片)。然后使用播放和暂停按钮暂停。

   $(document).ready(function() {
$('.carousel').carousel({
interval: 2000,
pause: "none"
});
});

关于javascript - Bootstrap 轮播重置为默认设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30129830/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com