我今天也想做同样的事情,当我搜索时,我来到了这个页面,但这个答案对我不起作用。下面给出了我是如何做到的。
我使用了 responsivecarousel:basilio.github.io/responsiveCarousel/#how-to-use
检查下面给出的示例。
<!DOCTYPE html>
<html>
<head>
<title>jquery grid carousel</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="http://basilio.github.io/responsiveCarousel/js/responsiveCarousel.js"></script>
<script>
jQuery(document).ready(function($){
$('.crsl-items').carousel();
});
</script>
<style>
img {
width: 80px;
}
</style>
</head>
<body>
<div id="NAV-ID" class="crsl-nav">
<a href="#" class="previous">Previous</a>
<a href="#" class="next">Next</a>
</div>
<div class="crsl-items" data-navigation="NAV-ID">
<div class="crsl-wrap">
<figure class="crsl-item">
<img src="http://basilio.github.io/responsiveCarousel/img/temp/sports.jpg">
<img src="http://basilio.github.io/responsiveCarousel/img/temp/sports.jpg"><br>
<img src="http://basilio.github.io/responsiveCarousel/img/temp/sports.jpg">
<img src="http://basilio.github.io/responsiveCarousel/img/temp/sports.jpg">
</figure>
<figure class="crsl-item">
<img src="http://basilio.github.io/responsiveCarousel/img/temp/nature.jpg">
<img src="http://basilio.github.io/responsiveCarousel/img/temp/nature.jpg"><br>
<img src="http://basilio.github.io/responsiveCarousel/img/temp/nature.jpg">
<img src="http://basilio.github.io/responsiveCarousel/img/temp/nature.jpg">
</figure>
<figure class="crsl-item">
<img src="http://basilio.github.io/responsiveCarousel/img/temp/food.jpg">
<img src="http://basilio.github.io/responsiveCarousel/img/temp/food.jpg"><br>
<img src="http://basilio.github.io/responsiveCarousel/img/temp/food.jpg">
<img src="http://basilio.github.io/responsiveCarousel/img/temp/food.jpg">
</figure>
</div>
</div>
</body>
</html>
测试:http: //jsfiddle.net/d59phwrt/
更新:
上一个解决方案的分页存在问题。所以我使用 owl-carousel 来做同样的事情。
http://owlgraphic.com/owlcarousel/index.html#how-to
此解决方案优于上述解决方案。示例代码如下。
<div id="owl-demo" class="owl-carousel">
<div class="item">
<img src="http://isc.stuorg.iastate.edu/wp-content/uploads/sample.jpg" />
<img src="http://isc.stuorg.iastate.edu/wp-content/uploads/sample.jpg" /><br>
<img src="http://isc.stuorg.iastate.edu/wp-content/uploads/sample.jpg" />
<img src="http://isc.stuorg.iastate.edu/wp-content/uploads/sample.jpg" />
</div>
<div class="item"><h1>2</h1></div>
<div class="item"><h1>3</h1></div>
<div class="item"><h1>4</h1></div>
</div>
<div class="customNavigation">
<a class="btn prev">Previous</a>
<a class="btn next">Next</a>
<a class="btn play">Autoplay</a>
<a class="btn stop">Stop</a>
</div>
<script src="../assets/js/jquery-1.9.1.min.js"></script>
<script src="../owl-carousel/owl.carousel.js"></script>
<!-- Demo -->
<style>
#owl-demo .item{
background: #3fbf79;
padding: 30px 0px;
margin: 10px;
color: #FFF;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
text-align: center;
}
.customNavigation{
text-align: center;
}
.customNavigation a{
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
</style>
<script>
$(document).ready(function() {
var owl = $("#owl-demo");
owl.owlCarousel({
items : 1, //10 items above 1000px browser width
itemsDesktop : [1000,5], //5 items between 1000px and 901px
itemsDesktopSmall : [900,3], // 3 items betweem 900px and 601px
itemsTablet: [600,2], //2 items between 600 and 0;
itemsMobile : false, // itemsMobile disabled - inherit from itemsTablet option
pagination : false
});
// Custom Navigation Events
$(".next").click(function(){
owl.trigger('owl.next');
})
$(".prev").click(function(){
owl.trigger('owl.prev');
})
$(".play").click(function(){
owl.trigger('owl.play',1000);
})
$(".stop").click(function(){
owl.trigger('owl.stop');
})
});
</script>