swiper全屏響應式自適應幻燈片代碼



256 1023 342



特效描述: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

加群請備注:從官網了解到

老夫子电子