此篇博客整理了常用的輪播效果,適用於所有開發人員 swipe是當下相對而言較好用的輪播插件,下麵是博主整理的demo源代碼,可直接上手(備註:需自己手動swipe所需的j和css) 此段代碼總共是有三個詳細效果,並且備註了初始化js對應的html,和使用swipe當中所需要用到的一些小的屬性控制方法 ...
此篇博客整理了常用的輪播效果,適用於所有開發人員
swipe是當下相對而言較好用的輪播插件,下麵是博主整理的demo源代碼,可直接上手(備註:需自己手動swipe所需的j和css)
此段代碼總共是有三個詳細效果,並且備註了初始化js對應的html,和使用swipe當中所需要用到的一些小的屬性控制方法!
這裡就不一一詳解
博客園開通很久,也一直沒時間好好經營自己的博客,第一篇博客,難免細節的地方,排列順序方法,內容介紹肯定難免存在許些問題,博主承諾以後會記錄的越來越優質
希望大家多多指教
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<title>公用效果</title> | |
<link rel="stylesheet" type="text/css" href="css/swiper.min.css"/> | |
<script src="js/swiper.min.js"></script> | |
<style type="text/css"> | |
li{ | |
list-style: none; | |
} | |
/*分頁器顏色樣式控制*/ | |
.swiper-pagination-bullet{ | |
background-color: #8a6b78 !important; | |
opacity: 1 !important; | |
} | |
.swiper-pagination-bullet-active{ | |
background-color: #e7cccc !important; | |
} | |
/*前後按鈕控制樣式*/ | |
.boxleft{ | |
background: url(img/gift-left.png) no-repeat !important; | |
background-size: 100%; | |
outline: none; | |
} | |
.boxright{ | |
background: url(img/gift-right.png) no-repeat !important; | |
background-size: 100%; | |
outline: none; | |
} /*outline: none;屬性可以去除點擊出現邊框*/ |
|
/*.*/ | |
/*滑鼠移出隱藏按鈕,移入顯示按鈕*/ | |
.swiper-container .hide{ | |
opacity:0; | |
} | |
.swiper-button-next,.swiper-button-prev{ | |
transition:opacity .5s; | |
} | |
/*.*/ | |
/*主圖下滾動*/ | |
#box { | |
width:1200px; | |
margin: 0 auto; | |
} | |
#box .swiper-wrapper{ | |
margin-top:40px ; | |
padding-left: 12px; | |
} | |
#box ul>li { | |
display: inline-block; | |
height: 100%; | |
box-sizing: border-box; | |
} | |
#box ul>li>img { | |
width: 170px; | |
height: 115px; | |
} | |
/*上下切換控制*/ | |
.smlbannertop{ | |
width: 400px; | |
} | |
.smlbannertop img { | |
width: 400px; | |
height: 305px; | |
} | |
.gallery-thumbs .swiper-slide { | |
height: 100%; | |
opacity: 0.8; | |
} | |
.gallery-thumbs .swiper-slide-thumb-active { | |
opacity: 1; | |
} | |
.smlbannerall{ | |
width: 1000px; | |
} | |
.smlbannerall img { | |
width: 176px; | |
height: 120px; | |
margin: 20px 0px 0 8px; | |
} | |
</style> | |
</head> | |
<body> | |
<!--top banner--> | |
<div class="swiper-container" id="bigbanner"> | |
<div class="swiper-wrapper"> | |
<div class="swiper-slide"><img src="img/banner01.jpg"></div> | |
<div class="swiper-slide"><img src="img/banner02.jpg"></div> | |
<div class="swiper-slide"><img src="img/banner03.jpg"></div> | |
</div> | |
<!--分頁器--> | |
<div class="swiper-pagination bigpagination"></div> | |
<!--前進後退按鈕--> | |
<div class="swiper-button-prev swiper-button-black bigleft"></div> | |
<div class="swiper-button-next swiper-button-black bigright"></div> | |
</div> | |
<!--主圖下滾動--> | |
<div class="swiper-container" style="width: 1300px; margin: 0 auto;"> | |
<div class="swiper-container" id="box"> | |
<ul class="swiper-wrapper"> | |
<li class="swiper-slide"> | |
<img src="img/choose1.jpg" /> | |
</li> | |
<li class="swiper-slide"> | |
<img src="img/choose2.jpg" /> | |
</li> | |
<li class="swiper-slide"> | |
<img src="img/choose3.jpg" /> | |
</li> | |
<li class="swiper-slide"> | |
<img src="img/choose4.jpg" /> | |
</li> | |
<li class="swiper-slide"> | |
<img src="img/choose5.jpg" /> | |
</li> | |
<li class="swiper-slide"> | |
<img src="img/choose3.jpg" /> | |
</li> | |
</ul> | |
</div> | |
<div class="swiper-button-prev boxleft"></div> | |
<div class="swiper-button-next boxright"></div> | |
</div> | |
<!--切換效果--> | |
<div class="swiper-container gallery-top smlbannertop"> | |
<div class="swiper-wrapper"> | |
<div class="swiper-slide"> | |
<img src="img/comrecommend.jpg" /> | |
</div> | |
<div class="swiper-slide"> | |
<img src="img/comrecommend.jpg" /> | |
</div> | |
<div class="swiper-slide"> | |
<img src="img/comrecommend.jpg" /> | |
</div> | |
<div class="swiper-slide"> | |
<img src="img/comrecommend.jpg" /> | |
</div> | |
</div> | |
</div> | |
<div class="swiper-container gallery-thumbs smlbannerall"> | |
<ul class="swiper-wrapper"> | |
<li class="swiper-slide"> | |
<img src="img/comrecommend01.jpg" /> | |
</li> | |
<li class="swiper-slide"> | |
<img src="img/comrecommend02.jpg" /> | |
</li> | |
<li class="swiper-slide"> | |
<img src="img/comrecommend03.jpg" /> | |
</li> | |
<li class="swiper-slide"> | |
<img src="img/comrecommend04.jpg" /> | |
</li> | |
</ul> | |
</div> | |
<script> | |
//topbanner | |
var mySwiper = new Swiper('#bigbanner', { | |
direction: 'horizontal', | |
//是否無限輪播 | |
loop: true, | |
//切換時間 | |
autoplay: { | |
delay: 3000, | |
disableOnInteraction: true,//用戶操作swiper之後,是否禁止autoplay。預設為true:停止。 | |
}, | |
//過渡時間 | |
speed: 1300, | |
// 如果需要分頁器 | |
pagination: { | |
el: '.bigpagination', | |
clickable :true, | |
}, | |
// 如果需要前進後退按鈕 | |
navigation: { | |
nextEl: '.bigright', | |
prevEl: '.bigleft', | |
}, | |
//切換效果 | |
effect:"fade" | |
}) | |
//滑鼠移出隱藏按鈕,移入顯示按鈕 | |
mySwiper.el.onmouseover=function(){ | |
mySwiper.navigation.$nextEl.removeClass('hide'); | |
mySwiper.navigation.$prevEl.removeClass('hide'); | |
} | |
mySwiper.el.onmouseout=function(){ | |
mySwiper.navigation.$nextEl.addClass('hide'); | |
mySwiper.navigation.$prevEl.addClass('hide'); | |
} | |
//主圖下滾動box | |
var swiper = new Swiper('#box', { | |
//顯示幾個盒子 | |
slidesPerView: 6, | |
//盒子之間的間距 | |
spaceBetween: 0, | |
autoplayDisableOnInteraction:true, | |
loop: true, | |
autoplay: { | |
delay: 2000 | |
}, | |
speed: 800, | |
// 如果需要前進後退按鈕 | |
navigation: { | |
nextEl: '.boxright', | |
prevEl: '.boxleft', | |
}, | |
}); | |
//切換效果 | |
var galleryThumbs = new Swiper('.smlbannerall', { | |
// 控制顯示幾個 | |
slidesPerView: 4, | |
loop: true, | |
loopedSlides: 5, //一般設置為本來slide的個數 | |
watchSlidesVisibility: true, | |
watchSlidesProgress: true, | |
}); | |
var galleryTop = new Swiper('.smlbannertop', { | |
spaceBetween: 10, | |
loop:true, | |
loopedSlides: 5, //一般設置為本來slide的個數 | |
thumbs: { | |
swiper: galleryThumbs, | |
}, | |
}); | |
</script> | |
</body> | |
</html> | |
此效果圖一一貼出