我对网络开发非常陌生......并尝试使用html5,css3和JavaScript创建图像滑块,左右导航按钮和播放/暂停切换,点击时更改,无论我点击效果都必须滑动导航或播放/暂停。
我想要的是将图像循环滑动......所以图像无休止地重复。
我尝试但无法正确实现......是否可以实现此功能以及可自定义的箭头和播放/暂停图像?
任何资源和代码都会有很多帮助。我想从头开始。
<!DOCTYPE HTML>
<html>
<head>
<link rel = "stylesheet" href = "bootstrap/css/bootstrap.min.css"
type="text/css">
<link rel = "stylesheet" href = "fontaws/font-awesome.min.css
type = "text/css">
<link rel = "stylesheet" href = "style.css" type = "text/css">
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3
/jquery.min.js"></script>
<script>
$(function () {
$('#homeCarousel').carousel({
interval:2000,
pause: "false"
});
$('#playButton').click(function () {
if($('#playSpan').hasClass("glyphicon glyphicon-play")){
$('#homeCarousel').carousel('cycle');
$('#playSpan').removeClass('glyphicon glyphicon-play');
$('#playSpan').addClass('glyphicon glyphicon-pause');
}
else{
$('#homeCarousel').carousel('pause');
$('#playSpan').removeClass('glyphicon glyphicon-pause');
$('#playSpan').addClass('glyphicon glyphicon-play');
}
});
});
</script>
</head>
<body>
<!-- Carousel -->
<div id="homeCarousel" class="carousel slide">
<!-- Items -->
<div class="carousel-inner">
<!-- Item 1 -->
<div class="item active">
<img src="img2.jpg"/>
</div>
<!-- Item 2 -->
<div class="item">
<img src="img3.jpg"/>
</div>
<!-- Item 3 -->
<div class="item">
<img src="img4.jpg" />
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#homeCarousel" role="button"
data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#homeCarousel" role="button"
data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true">
</span>
<span class="sr-only">Next</span>
</a>
<div id="carouselButtons">
<button id="playButton" type="button" class="btn btn-default btn-xs">
<span id="playSpan" class="glyphicon glyphicon-pause"></span>
</button>
</div>
</div>
</body>
</html>
答案 0 :(得分:0)
为什么不从现有的轮播脚本开始?类似于http://kenwheeler.github.io/slick/或http://sorgalla.com/jcarousel/。
答案 1 :(得分:0)
仅供参考:小提琴http://jsfiddle.net/KyleMit/XFcSv/已根据用户要求进行了更新
http://jsfiddle.net/XFcSv/896/
<!-- Carousel -->
<div id="homeCarousel" class="carousel slide">
<!-- Items -->
<div class="carousel-inner">
<!-- Item 1 -->
<div class="item active">
<img src="http://lorempixel.com/1500/600/abstract/1" />
<div class="container">
<div class="carousel-caption">
<h1>Bootstrap 3 Carousel Layout</h1>
<p>This is an example layout with carousel that uses the Bootstrap 3 styles.</p>
<p><a class="btn btn-lg btn-primary" href="http://getbootstrap.com">Learn More</a>
</p>
</div>
</div>
</div>
<!-- Item 2 -->
<div class="item">
<img src="http://lorempixel.com/1500/600/abstract/2" />
<div class="container">
<div class="carousel-caption">
<h1>Changes to the Grid</h1>
<p>Bootstrap 3 still features a 12-column grid, but many of the CSS class names have completely changed.</p>
<p><a class="btn btn-large btn-primary" href="#">Learn more</a></p>
</div>
</div>
</div>
<!-- Item 3 -->
<div class="item">
<img src="http://lorempixel.com/1500/600/abstract/3" />
<div class="container">
<div class="carousel-caption">
<h1>Percentage-based sizing</h1>
<p>With "mobile-first" there is now only one percentage-based grid.</p>
<p><a class="btn btn-large btn-primary" href="#">Browse gallery</a></p>
</div>
</div>
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#homeCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#homeCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
<div id="carouselButtons">
<button id="playButton" type="button" class="btn btn-default btn-xs">
<span id="playSpan" class="glyphicon glyphicon-pause"></span>
</button>
</div>
</div>
<!-- Post Info -->
<div style='position:fixed;bottom:0;left:0;
background:lightgray;width:100%;'>
About this SO Question: <a href='http://stackoverflow.com/q/20615100/1366033'>Add Play/Pause button to bootstrap carousel</a>
<br/> Find documentation: <a href='http://getbootstrap.com/css/'>Get Bootstrap 3.0</a>
<br/> Fork This Skeleton Here <a href='http://jsfiddle.net/KyleMit/kcpma/'>Bootrsap 3.0 Skeleton</a>
<br/>
<div>
$(function() {
$('#homeCarousel').carousel({
interval: 2000,
pause: "false"
});
$('#playButton').click(function() {
if ($('#playSpan').hasClass("glyphicon glyphicon-play")) {
$('#homeCarousel').carousel('cycle');
$('#playSpan').removeClass('glyphicon glyphicon-play');
$('#playSpan').addClass('glyphicon glyphicon-pause');
} else {
$('#homeCarousel').carousel('pause');
$('#playSpan').removeClass('glyphicon glyphicon-pause');
$('#playSpan').addClass('glyphicon glyphicon-play');
}
});
});
#carouselButtons {
margin-left: 280px;
position: absolute;
bottom: 6px;
}