swiper全屏响应式自适应幻灯片代码



223 888 297



特效描述:swiper 全屏响应式 自适应幻灯片,swiper全屏响应式自适应幻灯片代码

代码结构

1. 引入CSS

<link rel="stylesheet" href="css/swiper.min.css">
<link rel="stylesheet" href="css/swiper.min.css">

2. 引入JS

<script src="js/jquery.min.js"></script>
<script src="js/swiper.min.js"></script>
<script src="js/jquery.min.js"></script>
<script src="js/swiper.min.js"></script>

3. HTML代码

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>swiper全屏响应式幻灯片代码 - 站长素材</title>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
<style>
* {
	padding: 0;
	margin: 0;
}
	body{background-color: #252525}
.clearfix:after {
	visibility: hidden;
	display: block;
	content: "";
	height: 0;
	line-height: 0;
	clear: both;
}
.clearfix {
	zoom: 1;
}
html, body {
	position: relative;
	height: 100%;
}
body {
	font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
	font-size: 14px;
	color: #000;
	margin: 0;
	padding: 0;
}
.swiper-container {
	width: 100%;
	margin-left: auto;
	margin-right: auto;
}
.gallery-top {
	padding-bottom: 12px;
	width: 100%;
}
.gallery-top .swiper-slide {
	max-width: 100%;
	max-width: 100%;
	width: auto;
	overflow: hidden;
	opacity: 0.5;
}
.gallery-top .swiper-slide img {
	max-width: 100%;
	height: 100%;
}
.gallery-top .swiper-slide-active {
	opacity: 1;
}
.gallery-thumbs {
	height: 65px;
	box-sizing: border-box;
	padding-top: 2px;
}
.gallery-thumbs .swiper-slide {
	max-width: 100%;
	max-height: 100%;
	width: auto;
	height: 100%;
	overflow: hidden;
}
.gallery-thumbs .swiper-slide img {
	max-width: 100%;
	height: 100%;
}
.gallery-thumbs-box {
	position: relative;
	width: 100%;
	height: 65px;
}
.gallery-thumbs-box .swiper-container {
	margin-left: auto;
	margin-right: auto;
}
.gallery-thumbs-box .swiper-button-prev {
	background-image: url(images/left-small.png);
	width: 10px;
	height: 65px;
	background-size: 10px 18px;
	left: 10px;
	margin-top: 0;
	top: 0;
	outline: none;
}
.gallery-thumbs-box .swiper-button-next {
	background-image: url(images/next-small.png);
	width: 10px;
	height: 65px;
	background-size: 10px 18px;
	right: 10px;
	margin-top: 0;
	top: 0;
	outline: none;
}
.gallery-top-box {
	position: relative;
	width: 100%;
}
.gallery-top-box .swiper-container {
	margin-left: auto;
	margin-right: auto;
}
.gallery-top-box .swiper-button-prev {
	background-image: url(images/left-lg.png);
	width: 18px;
	background-size: 18px 38px;
	left: 10px;
	margin-top: 0;
	top: 50%;
	outline: none;
	transform: translate(0, -50%)
}
.gallery-top-box .swiper-button-next {
	background-image: url(images/next-lg.png);
	width: 18px;
	background-size: 18px 38px;
	right: 10px;
	margin-top: 0;
	top: 50%;
	outline: none;
	transform: translate(0, -50%)
}
.slideshow {
	float: right;
	margin-right: 30px;
	margin-top: 15px;
	display: inline-block;
	background-repeat: no-repeat;
	background-position: center right;
	background-image: url("images/play.png");
	cursor: pointer;
	padding-right: 15px;
	color: #999;
	transition: all 0.3s ease
}
.pauseed {
	background-image: url("images/pause.png");
}
</style>
</head>
<body >
<div class="headernav" style="height:86px;line-height:86px;text-align:center;overflow:hidden;">
	<h2>导航</h2>
</div>
<!-- Swiper -->
<div class="gallery-top-box">
	<div class="swiper-container gallery-top">
		<div class="swiper-wrapper">
			<div class="swiper-slide" data-id="1"> <img src="images/a1.png"> </div>
			<div class="swiper-slide" data-id="2"> <img src="images/a2.png"> </div>
			<div class="swiper-slide" data-id="3"> <img src="images/a3.png"> </div>
			<div class="swiper-slide" data-id="4"> <img src="images/a4.png"> </div>
			<div class="swiper-slide" data-id="5"> <img src="images/a5.png"> </div>
			<div class="swiper-slide" data-id="6"> <img src="images/a6.png"> </div>
			<div class="swiper-slide" data-id="7"> <img src="images/a1.png"> </div>
			<div class="swiper-slide" data-id="8"> <img src="images/a2.png"> </div>
			<div class="swiper-slide" data-id="9"> <img src="images/a3.png"> </div>
			<div class="swiper-slide" data-id="10"> <img src="images/a4.png"> </div>
			<div class="swiper-slide" data-id="11"> <img src="images/a5.png"> </div>
			<div class="swiper-slide" data-id="12"> <img src="images/a6.png"> </div>
			<div class="swiper-slide" data-id="13"> <img src="images/a1.png" > </div>
			<div class="swiper-slide" data-id="14"> <img src="images/a2.png"> </div>
			<div class="swiper-slide" data-id="15"> <img src="images/a3.png"> </div>
			<div class="swiper-slide" data-id="16"> <img src="images/a4.png"> </div>
			<div class="swiper-slide" data-id="17"> <img src="images/a5.png"> </div>
			<div class="swiper-slide" data-id="18"> <img src="images/a6.png"> </div>
			<div class="swiper-slide" data-id="19"> <img src="images/a1.png" > </div>
			<div class="swiper-slide" data-id="20"> <img src="images/a2.png"> </div>
			<div class="swiper-slide" data-id="21"> <img src="images/a3.png"> </div>
			<div class="swiper-slide" data-id="22"> <img src="images/a4.png"> </div>
			<div class="swiper-slide" data-id="23"> <img src="images/a5.png"> </div>
			<div class="swiper-slide" data-id="24"> <img src="images/a6.png"> </div>
		</div>
		<div class="swiper-scrollbar"></div>
	</div>
	<div class="swiper-button-prev"></div>
	<div class="swiper-button-next"></div>
</div>
<div class="gallery-thumbs-box">
	<div class="swiper-container gallery-thumbs">
		<div class="swiper-wrapper">
			<div class="swiper-slide" data-id="1"> <img src="images/a1.png"> </div>
			<div class="swiper-slide" data-id="2"> <img src="images/a2.png"> </div>
			<div class="swiper-slide" data-id="3"> <img src="images/a3.png"> </div>
			<div class="swiper-slide" data-id="4"> <img src="images/a4.png"> </div>
			<div class="swiper-slide" data-id="5"> <img src="images/a5.png"> </div>
			<div class="swiper-slide" data-id="6"> <img src="images/a6.png"> </div>
			<div class="swiper-slide" data-id="7"> <img src="images/a1.png"> </div>
			<div class="swiper-slide" data-id="8"> <img src="images/a2.png"> </div>
			<div class="swiper-slide" data-id="9"> <img src="images/a3.png"> </div>
			<div class="swiper-slide" data-id="10"> <img src="images/a4.png"> </div>
			<div class="swiper-slide" data-id="11"> <img src="images/a5.png"> </div>
			<div class="swiper-slide" data-id="12"> <img src="images/a6.png"> </div>
			<div class="swiper-slide" data-id="13"> <img src="images/a1.png" > </div>
			<div class="swiper-slide" data-id="14"> <img src="images/a2.png"> </div>
			<div class="swiper-slide" data-id="15"> <img src="images/a3.png"> </div>
			<div class="swiper-slide" data-id="16"> <img src="images/a4.png"> </div>
			<div class="swiper-slide" data-id="17"> <img src="images/a5.png"> </div>
			<div class="swiper-slide" data-id="18"> <img src="images/a6.png"> </div>
			<div class="swiper-slide" data-id="19"> <img src="images/a1.png" > </div>
			<div class="swiper-slide" data-id="20"> <img src="images/a2.png"> </div>
			<div class="swiper-slide" data-id="21"> <img src="images/a3.png"> </div>
			<div class="swiper-slide" data-id="22"> <img src="images/a4.png"> </div>
			<div class="swiper-slide" data-id="23"> <img src="images/a5.png"> </div>
			<div class="swiper-slide" data-id="24"> <img src="images/a6.png"> </div>
		</div>
	</div>
	<div class="swiper-button-prev"></div>
	<div class="swiper-button-next"></div>
</div>
<!-- Swiper -->
<div class="footernav clearfix" style="height:32px;overflow:hidden;">
  <div class="slideshow">slideshow</div>
</div>
<!-- Swiper JS --> 
<script src="js/swiper.min.js"></script> 
<script>
  	//图片等比例
	galleryTopHeight()
	$(window).resize(function(){
		galleryTopHeight()
	})
    var galleryTop = new Swiper('.gallery-top-box .gallery-top', {
	  centeredSlides: true,
	  autoplay:{
		delay:4000,
		disableOnInteraction: false 
	  },
	  slidesPerView: 'auto',
      spaceBetween: 10,
      navigation: {
        nextEl: '.gallery-top-box .swiper-button-next',
        prevEl: '.gallery-top-box .swiper-button-prev',
      },
	  scrollbar: {
        el: '.swiper-scrollbar',
        hide: false,
		draggable: true,
		dragSize:150,
      }
    });
	$(".slideshow").click(function(){
		if($(this).hasClass("pauseed")){
			//播放
			$(this).removeClass("pauseed")
			galleryTop.autoplay.start()
		}else{
			//暂停
			$(this).addClass("pauseed")
			galleryTop.autoplay.stop()
		}
	})
	galleryTop.scrollbar.$el.css({
		"bottom":"0px",
		"background":"none",
		"height":"5px"
	});
	galleryTop.scrollbar.$dragEl.css({
		'background':'rgba(171,171,171,171.6)'
	}); 
	galleryTop.scrollbar.updateSize();
    var galleryThumbs = new Swiper('.gallery-thumbs-box .gallery-thumbs', {
      spaceBetween: 10,
      slidesPerView: 'auto',
      touchRatio: 0.2,
	  navigation: {
        nextEl: '.gallery-thumbs-box .swiper-button-next',
        prevEl: '.gallery-thumbs-box .swiper-button-prev',
      }
    });
	galleryTop.controller.control = galleryThumbs;
	<!--注意添加objThumbs,objTop对应的索引值1 ~ N -->
	var objThumbs = $(".gallery-thumbs .swiper-wrapper .swiper-slide");
	var objTop = $(".gallery-top .swiper-wrapper .swiper-slide");
	objThumbs.click(function(e){
		var currentId = $(this).attr("data-id");
		for(var i = 0 ; i< objTop.length; i++){
			if($(objTop[i]).attr("data-id") === currentId){
				$(objTop[i-1]).addClass("swiper-slide-prev")
				$(objTop[i-1]).siblings().removeClass("swiper-slide-prev")
				$(objTop[i]).addClass("swiper-slide-active")
				$(objTop[i]).siblings().removeClass("swiper-slide-active")
				$(objTop[i+1]).addClass("swiper-slide-next")
				$(objTop[i+1]).siblings().removeClass("swiper-slide-next")
				e.preventDefault();
				galleryTop.slideTo(i,1000, false);
			}
		}
	})
	function galleryTopHeight(){
		//处理图片比例
		var wh = $(window).height();
		var headernav_height = $(".headernav").height()
		var footernav_height = $(".footernav").height()
		var galleryThumbs_height = $(".gallery-thumbs").height()
		var galleryTop_height = wh - galleryThumbs_height - headernav_height - footernav_height - 22
		$(".gallery-top").css("height",galleryTop_height)
		//缩略图
		var galleryThumbs_width = $(window).width() - 60
		$(".gallery-thumbs-box .swiper-container").css("width",galleryThumbs_width)
		//大图
		var galleryTop_width = $(window).width() - 80
		$(".gallery-top-box .swiper-container").css("width",galleryTop_width)
	}
</script>
</body>
</html>



用户评论
大牛,别默默的看了,快登录帮我点评一下吧!:)      登录 | 注册


热门标签: flash焦点图 flash幻灯片 flashbanner flash图片轮播 滑动选项卡 滑动切换 滚动切换 滚动条切换 滑动手风琴 选项卡切换 选项卡 切换 tab切换 页面切换 选项卡插件 切换插件 全屏焦点图 全屏切换 切换按钮 宽屏全屏 宽屏 全屏 页面全屏 页面宽屏 表单 表单美化 表单插件 表单美化插件 焦点图 幻灯片 轮播图 bar焦点图 图片全屏 带缩略图的幻灯片 图片切换 图片选项卡 图标选项卡 纯图片轮播 图片轮播 全屏焦点图 按钮控制

×
×

注册

官方QQ群

扫描上面二维码加微信群

官方QQ群

jQuery/js讨论群
群号:642649996
Css3+Html5讨论群
群号:322131262

加群请备注:从官网了解到