我正在引导中使用jquery和javascript执行轮播播放和暂停。我已经编写了代码,但没有到达错过的地方。 这是完整的代码,可能会让您发现我的错误。 问题在于,用于播放和暂停的按钮在轮播范围内,并且按钮通常给出的行为在此处不相同。 对于当前情况,按钮位于prev按钮下方,并执行与prev正在执行的相同操作,即显示前一个图像。
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags always come first -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="node_modules/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="node_modules/bootstrap-social/bootstrap-social.css">
<link rel="stylesheet" href="css/styles.css">
<title>Ristorante Con Fusion</title>
</head>
<body>
<div class="container">
<div class="row row-content">
<div class="col">
<div id="mycarousel" class="carousel slide" data-ride="carousel">
<div class="carousel-inner" role="listbox">
<div class="carousel-item active">
<img class="d-block img-fluid"
src="img/uthappizza.png" alt="uthappizza">
<div class="carousel-caption d-none d-md-block">
<h2>Uthappizza<span class="badge badge-danger">HOT</span><span class="badge badge-pill badge-secondary">$4.99</span></h2>
<p class="d-none d-sm-block">A unique combination of Indian Uthappam</p>
</div>
</div>
<div class="carousel-item">
<img class="d-block img-fluid"
src="img/buffet.png" alt="buffet">
<div class="carousel-caption d-none d-md-block">
<h2>Weekend Grand Buffet<span class="badge badge-danger">NEW</span></h2>
<p class="d-none d-sm-block">Featuring mouthwatering combinations with a choice of five different salads.</p>
</div>
</div>
<div class="carousel-item">
<img class="d-block img-fluid"
src="img/alberto.png" alt="alberto">
<div class="carousel-caption d-none d-md-block">
<h2>Alberto Somayya</h2>
<h4>Executive Chef</h4>
<p class="d-none d-sm-block">Award winning three-star Michelin chef with wide International experience.</p>
</div>
</div>
</div>
<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>
</ol>
<a class="carousel-control-prev" href="#mycarousel" role="button" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#mycarousel" role="button" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
<div class="btn-group" id="carouselButton">
<button class="btn btn-danger btn-sm" id="carousel-pause">
<span class="fa fa-pause"></span>
</button>
<button class="btn btn-danger btn-sm" id="carousel-play">
<span class="fa fa-play"></span>
</button>
</div>
</div>
</div>
</div>
<div class="row row-content align-items-center">
<div class="col-12 col-sm-4 order-sm-last col-md-3">
<h3>Our Lipsmacking Culinary Creations</h3>
</div>
<div class="col col-sm order-sm-first col-md">
<div class="media">
<img class="d-flex mr-3 img-thumbnail align-self-center" src="img/uthappizza.png" alt="uthappizza">
<div class="media-body">
<h2 class="mt-0">Uthappizza<span class="badge badge-danger">HOT</span><span class="badge badge-pill badge-secondary">$4.99</span></h2>
<p>A unique combination of Indian Uthappam (pancake) and Italian pizza.</p>
</div>
</div>
</div>
</div>
<div class="row row-content align-items-center">
<div class="col-12 col-sm-4 col-md-3">
<h3>This Month's Promotions</h3>
</div>
<div class="col col-sm col-md">
<div class="media">
<img class="d-flex order-sm-last mr-3 img-thumbnail align-self-center" src="img/buffet.png" alt="buffet">
<div class="media-body">
<h2 class="mt-0">Weekend Grand Buffet<span class="badge badge-danger">NEW</span></h2>
<p>Featuring mouthwatering combinations with a choice of five different salads.</p>
</div>
</div>
</div>
</div>
<div class="row row-content align-items-center">
<div class="col-12 col-sm-4 order-sm-last col-md-3">
<h3>Meet our Culinary Specialists</h3>
</div>
<div class="col col-sm col-md order-sm-first">
<div class="media">
<img class="d-flex mr-3 img-thumbnail align-self-center" src="img/alberto.png" alt="alberto">
<div class="media-body">
<h2 class="mt-0">Alberto Somayya<span class="badge badge-danger">Exclusive</span><span class="badge badge-pill badge-secondary">$4.99</span></h2>
<h4>Executive Chef</h4>
<p>Award winning three-star Michelin chef with wide International experience.</p>
</div>
</div>
</div>
</div>
</div>
<!-- jQuery first, then Popper.js, then Bootstrap JS. -->
<script src="node_modules/jquery/dist/jquery.slim.min.js"></script>
<script src="node_modules/popper.js/dist/umd/popper.min.js"></script>
<script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<script>
$(document).ready(function(){
$('#mycarousel').carousel({ interval : 2000 });
$('#carousel-pause').click(function(){
$('#mycarousel').carousel('pause');
});
$('#carousel-play').click(function(){
$('#mycarousel').carousel('cycle');
});
});
</script>
</body>
</html>
轮播播放和暂停的正确行为。
答案 0 :(得分:0)
是的,伙计,我从Coursera修读课程时也遇到问题。 jQuery并不是问题。将“ carouselButton”的“ z-index”设置为2或更高,并且应该可以使用
答案 1 :(得分:0)
浏览完脚本后,我发现您选择了代码中的一个重要细节,即您没有添加暂停:interval:2000之后为false。因此您的脚本代码应该以这种方式显示。
windows-community-toolkit
或者您可以利用它
public PrintHelper PrintHelper;
public void StartPrint(Panel container, List<CompanyDetail> PrintSampleItems)
{
try
{
PrintHelper = new PrintHelper(container);
PrintHelper.OnPrintSucceeded += PrintHelper_OnPrintSucceeded;
PrintHelper.OnPrintFailed += PrintHelper_OnPrintFailed;
PrintHelper.OnPreviewPagesCreated += PrintHelperOnOnPreviewPagesCreated;
var pageNumber = 0;
var data = PrintSampleItems;
var grid = new Grid();
grid.RowDefinitions.Add(new RowDefinition() {Height = GridLength.Auto});
grid.RowDefinitions.Add(new RowDefinition() {Height = new GridLength(1, GridUnitType.Star)});
grid.RowDefinitions.Add(new RowDefinition() {Height = GridLength.Auto});
// Static header
var header = new TextBlock
{
Text = "Departments Print",
Margin = new Thickness(0, 0, 0, 20),
HorizontalAlignment = HorizontalAlignment.Center,
FontSize = 18,
FontWeight = FontWeights.Bold
};
Grid.SetRow(header, 0);
grid.Children.Add(header);
var dataGrid = new CompanyDetailReportTemplateControl
{
HorizontalAlignment = HorizontalAlignment.Center
};
dataGrid.SetValues(PrintSampleItems);
Grid.SetRow(dataGrid, 1);
grid.Children.Add(dataGrid);
// Footer with page number
pageNumber++;
var footer = new TextBlock
{
Text = $"Page [ {pageNumber} ]", Margin = new Thickness(0, 20, 0, 0),
HorizontalAlignment = HorizontalAlignment.Right
};
Grid.SetRow(footer, 2);
grid.Children.Add(footer);
PrintHelper.AddFrameworkElementToPrint(grid);
}
catch
{
}
}
当您单击“暂停”或“播放”按钮时,两种方式都可以启动并正常运行代码
答案 2 :(得分:0)
是的...将z-index: 1;
设置为carouselButton
...肯定可以。