以下是 jQuery 3D堆叠式图片切换代码 的示例演示效果:
部分效果截图:
HTML代码(index.html):
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery 3D堆叠式图片切换代码</title>
<link rel="stylesheet" href="css/style.css"/>
</head>
<body>
<div class="container">
<div class="hub-slider">
<div class="hub-slider-slides">
<ul>
<li>1 test</li>
<li>2 test</li>
<li>3 test</li>
<li>4 test</li>
</ul>
</div>
<div class="hub-slider-controls">
<button class="hub-slider-arrow hub-slider-arrow_next">↑</button>
<button class="hub-slider-arrow hub-slider-arrow_prev">↓</button>
</div>
</div>
</div>
<script src="js/jquery-1.11.0.min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/hubslider.js"></script>
<script type="text/javascript">
$(function () {
$('.hub-slider-slides ul').hubSlider({
selector: $('li'),
button: {
next: $('.hub-slider-arrow_next'),
prev: $('.hub-slider-arrow_prev')
},
transition: '0.7s',
startOffset: 30,
auto: true,
time: 2 // secondly
});
})
</script>
</body>
</html>
JS代码(hubslider.min.js):
/** * Created by ufukOzarslan & burakErmeydan on 26.04.16. */
jQuery.fn.hubSlider=function(t){
var e=jQuery.extend({
selector:null,button:{
next:null,prev:null}
,opacity:1,opacityStep:.2,startOffset:20,offset:0,scale:1,scaleStep:"0.05",transition:"0.6s",auto:!1,time:3}
,t);
try{
var r=this,n=r.find(e.selector).length,s=[];
(null===e.selector||""==e.selector)&&console.error("Error,specify selector!"),r.find(e.selector).each(function(t){
r.find(e.selector).eq(t).css({
"z-index":n,top:-e.offset,"-webkit-transform":"scale("+e.scale+")","-moz-transform":"scale("+e.scale+")","-ms-transform":"scale("+e.scale+")","-o-transform":"scale("+e.scale+")",transform:"scale("+e.scale+")"}
).attr("data-key",t),e.scale=e.scale-e.scaleStep,n-=0===t?t+1:t,e.offset=e.offset+e.startOffset,t+1<=r.find(e.selector).length&&(r.find(e.selector).eq(t).css({
opacity:e.opacity}
),e.opacity=e.opacity-e.opacityStep)}
);
var a=function(t){
r.find(e.selector).each(function(n){
var a=$(this).attr("data-key"),o=null;
"next"==t?(o=r.find(e.selector).eq(n-1).attr("style"),"0"!=a?$(this).attr("data-key",parseFloat(a)-1):$(this).attr("data-key",parseFloat(r.find(e.selector).length)-1)):"prev"==t&&(n>=parseFloat(r.find(e.selector).length)-1&&(n=-1),o=r.find(e.selector).eq(n+1).attr("style"),a<parseFloat(r.find(e.selector).length)-1?$(this).attr("data-key",parseFloat(a)+1):$(this).attr("data-key",0)),s.push(o)}
),r.find(e.selector).each(function(t){
$(this).attr("style",s[t]).css({
transition:e.transition,"-webkit-transition":e.transition,"transform-style":"flat","-webkit-transform-style":"flat"}
)}
),s.length=0}
;
(null===e.button.next||""==e.button.next&&null===e.button.prev||""==e.button.prev)&&console.error("Error,button specify selector!"),e.button.next.click(function(t){
a("next")}
),e.button.prev.click(function(t){
a("prev")}
),e.auto===!0&&((null===e.time||""==e.time)&&console.error("Error,time specify selector!"),r.interval=setInterval(function(){
a("next")}
,1e3*e.time),r.hover(function(){
clearInterval(r.interval),r.interval=null}
,function(){
r.interval=setInterval(function(){
a("next")}
,1e3*e.time)}
))}
catch(o){
console.error(o)}
}
;
CSS代码(style.css):
.container{width:800px;margin:80px auto;}
.hub-slider{position:relative;}
.hub-slider ul{list-style:none;}
.hub-slider ul li{width:800px;height:445px;background:#add8e6;position:absolute;left:0;top:0;background-size:cover;}
.hub-slider ul li:nth-child(1){background-image:url(../img/1.jpg);}
.hub-slider ul li:nth-child(2){background-image:url(../img/2.jpg);}
.hub-slider ul li:nth-child(3){background-image:url(../img/3.jpg);}
.hub-slider ul li:nth-child(4){background-image:url(../img/4.jpg);}
.hub-slider-controls{position:absolute;right:0;top:0;z-index:1000;}
.hub-slider-arrow{width:40px;height:40px;border:none;background:#d2527f;color:#fff;font-weight:bold;}