以下是 类似播放器的jQuery图片切换特效代码 的示例演示效果:
部分效果截图:
HTML代码(index.html):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>类似播放器的jQuery图片切换</title>
<link href="img/site/Site.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery.min.js"></script>
<link href="css/slider.css" rel="stylesheet" type="text/css" />
<link href="css/js-image-slider.css" rel="stylesheet" type="text/css" />
<script src="js/js-image-slider.js" type="text/javascript"></script>
<script src="js/thumbnail-slider.js" type="text/javascript"></script>
<style type="text/css">
#dm1Inner {margin:20px 0 0 90px;}
.floatLeft {float:left;}
h3 {margin-top:0;color:#333;}
.sep2 {width:800px;margin:30px auto 5px;border-bottom:solid 2px #E3E3E3;height:0;overflow:hidden;}
</style>
</head>
<body>
<div id="main">
<div id="dm"></div>
<div id="dm1">
<div id="dm1Inner">
<div class="floatLeft">
<div id="sliderFrame">
<div id="slider">
<img src="images/slider-1.jpg" alt="#slideshow-1" title="Welcome to Menucool jQuery Slideshow" />
<img src="images/slider-2.jpg" alt="#slideshow-2" />
<a href="#"><img src="images/slider-3.jpg" alt="#slideshow-3" /></a>
<img src="images/slider-4.jpg" alt="#slideshow-4" />
<img src="images/slider-5.jpg" alt="#slideshow-5" />
<img src="images/slider-6.jpg" alt="#slideshow-6" />
<img src="images/slider-7.jpg" alt="#slideshow-7" />
<img src="images/slider-8.jpg" alt="#slideshow-8" />
<img src="images/slider-9.jpg" alt="#slideshow-9" />
<img src="images/slider-10.jpg" alt="#slideshow-10"/>
<img src="images/slider-11.jpg" alt="#slideshow-11"/>
<img src="images/slider-12.jpg" alt="#slideshow-12"/>
</div>
</div>
</div>
<div class="floatLeft">
<div id="mcts1">
<img src="images/slideshow-1s.jpg" />
<img src="images/slideshow-2s.jpg" />
<img src="images/slideshow-3s.jpg" />
<img src="images/slideshow-4s.jpg" />
<img src="images/slideshow-5s.jpg" />
<img src="images/slideshow-6s.jpg" />
<img src="images/slideshow-7s.jpg" />
<img src="images/slideshow-8s.jpg" />
<img src="images/slideshow-9s.jpg" />
<img src="images/slideshow-10s.jpg" />
<img src="images/slideshow-11s.jpg" />
<img src="images/slideshow-12s.jpg" />
</div>
</div>
<div style="clear:both;"></div>
<div style="display:none;">
<div id="slideshow-1">
<h3>Welcome to Menucool jQuery Slideshow</h3>
This demo shows how the jQuery slideshow (or Thumbnail Slider if using the pure JavaScript) can work together with the JavaScript Image Slider.
</div>
<div id="slideshow-2">
<h3>Enhanced Slideshow Effect</h3>
The jQuery Slideshow/thumbnail slider works nicely together with the JavaScript Image Slider which greatly enhanced the slideshow with an added aesthetic appeal.
</div>
<div id="slideshow-3">
<h3>SEO Friendly</h3>
The markup is valid HTML5 and SEO optimzied, with all content always being available to search engines.
</div>
<div id="slideshow-4">
<h3>A Tool for Web Designer</h3>
Its goal is to simplify the process of creating professional image/content slideshow for the web and mobile devices. This jQuery Slideshow will entertain your audience while scrolling what feature your website has.
</div>
<div id="slideshow-5">
<h3>JavaScript Image Slider is driven by the jQuery/Thumbnail Slideshow</h3>
Each slide of the JavaScript Image Slider is triggered by the thumbnail scrolling.
</div>
<div id="slideshow-6">
<h3>Rich HTML</h3>
Rich HTML content can be added to the thumbnails, or to the description of each JavaScript Image Slider slide.
</div>
<div id="slideshow-7">
<h3>Fully Customizable</h3>
The jQuery Slideshow, or Thumbnail Slider if using the pure JavaScript, can be horizontal or vertical, and its styles and behaviors are fully customizable by tweaking the CSS and the JavaScipt.
</div>
<div id="slideshow-8">
<h3>Varying Width, or Varying Height</h3>
The varying size (either varying width for the horizontal jQuery slideshow, or varying height for the vertical slider) is allowed for the thumbnails.
</div>
<div id="slideshow-9">
<h3>A Great Way to Showcase Your Products</h3>
It is a perfect way to showcase your products. This script allows you to easily animate any series of elements, by sequentially scrolling them.
</div>
<div id="slideshow-11">
<h3>Wide Browsers and Devices Support</h3>
The carousel is completely configurable and compatible with all major browsers (including ie6+, Firefox Chrome, Opera, Safari) and mobile platforms like iphone / ipad.
</div>
<div id="slideshow-12">
<h3>A Great Carousel</h3>
Use this stunning carousel to entertain your readers while scrolling what feature your website has. It has a very smooth user interface that gives your slider an added aesthetic appeal.
</div>
<div id="slideshow-10">
<h3>Easy to Use</h3>
Enhance your website by adding a unique and attractive slider! And it is easy: download, copy & paster, tweak the styles to your desires. Well, that's it.
</div>
</div>
</div>
</div>
</div>
</body>
</html>
JS代码(thumbnail-slider.js):
var mct1_Options ={
sliderId:"mcts1",direction:"vertical",scrollInterval:2100,scrollDuration:600,hoverPause:true,autoAdvance:true,scrollByEachThumb:true,circular:true,largeImageSlider:imageSlider,inSyncWithLargeImageSlider:true,license:"b2e98"}
;
var thumbnailSlider = new ThumbnailSlider(mct1_Options);
/* Menucool Thumbnail Slider v2013.12.15. Copyright www.menucool.com */
function ThumbnailSlider(e){
var g="length",i="className",T=function(a,c){
var b=a[g];
while(b--)if(a[b]===c)return true;
return false}
,U=function(b,a){
return T(b[i].split(" "),a)}
,M=function(a,b){
if(!U(a,b))if(a[i]=="")a[i]=b;
else a[i]+=" "+b}
,K=function(a,b){
var c=new RegExp("(^| )"+b+"( |$)");
a[i]=a[i].replace(c,"$1");
a[i]=a[i].replace(/ $/,"")}
,Q=function(b,c){
var a=null;
if(typeof b.currentStyle!="undefined")a=b.currentStyle;
else a=document.defaultView.getComputedStyle(b,null);
return a[c]}
,p="largeImageSlider",s="appendChild",E="inSyncWithLargeImageSlider",u=function(d){
var a=d.childNodes,c=[];
if(a)for(var b=0,e=a[g];
b<e;
b++)a[b].nodeType==1&&c.push(a[b]);
return c}
,Z=function(b,c){
var a=c==0?b.nextSibling:b.firstChild;
while(a&&a.nodeType!=1)a=a.nextSibling;
return a}
,S=function(a,c,b){
if(a.addEventListener)a.addEventListener(c,b,false);
else a.attachEvent&&a.attachEvent("on"+c,b)}
,j="style",k="offsetTop",l="offsetLeft",t="offsetHeight",A="offsetWidth",x="onmouseover",w="onmouseout",D=function(){
this.b=[];
this.c=null;
this.d()}
;
function L(){
var c=50,b=navigator.userAgent,a;
if((a=b.indexOf("MSIE "))!=-1)c=parseInt(b.substring(a+5,b.indexOf(".",a)));
return c}
var W=L()<9,F=L()<8,O=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
D.a={
g:function(a){
return-Math.cos(a*Math.PI)/2+.5}
,h:function(a){
return a}
,i:function(b,a){
return Math.pow(b,a*2)}
,j:function(b,a){
return 1-Math.pow(1-b,a*2)}
}
;
var Y=["$1$2$3","$1$2$3","$1$24","$1$23","$1$22"];
D.prototype={
k:{
b:e.scrollDuration,a:function(){
}
,e:D.a.g,d:1}
,d:function(){
for(var b=["webkit","moz","ms","o"],a=0;
a<b[g]&&!window.requestAnimationFrame;
++a){
window.requestAnimationFrame=window[b[a]+"RequestAnimationFrame"];
window.cancelAnimationFrame=window[b[a]+"CancelAnimationFrame"]||window[b[a]+"CancelRequestAnimationFrame"]}
this.supportAnimationFrame=!!window.requestAnimationFrame}
,m:function(h,d,g,c){
for(var b=[],i=g-d,j=g>d?1:-1,f=Math.ceil(60*c.b/1e3),a,e=1;
e<=f;
e++){
a=d+c.e(e/f,c.d)*i;
if(h!="opacity")a=Math.round(a);
b.push(a)}
b.index=0;
return b}
,n:function(){
this.c==null&&this.o()}
,o:function(){
this.p();
var a=this;
this.c=this.supportAnimationFrame?window.requestAnimationFrame(function(){
a.o()}
):window.setInterval(function(){
a.p()}
,15)}
,p:function(){
var a=this.b[g];
if(a){
for(var c=0;
c<a;
c++)this.q(this.b[c]);
while(a--){
var b=this.b[a];
if(b.c.index==b.c[g]){
b.d();
this.b.splice(a,1)}
}
}
else{
if(this.supportAnimationFrame)window.cancelAnimationFrame(this.c);
else window.clearInterval(this.c);
this.c=null}
}
,q:function(a){
if(a.c.index<a.c[g]){
var c=a.b,b=a.c[a.c.index];
if(a.b=="opacity"){
if(W){
c="filter";
b="alpha(opacity="+Math.round(b*100)+")"}
}
else b+="px";
a.a[j][c]=b;
a.c.index++}
}
,r:function(e,b,d,f,a){
a=this.s(this.k,a);
var c=this.m(b,d,f,a);
this.b.push({
a:e,b:b,c:c,d:a.a}
);
this.n()}
,s:function(c,b){
b=b||{
}
;
var a,d={
}
;
for(a in c)d[a]=b[a]!==undefined?b[a]:c[a];
return d}
}
;
var N=new D;
function R(b){
var a=[],c=b[g];
while(c--)a.push(String.fromCharCode(b[c]));
return a.join("")}
var a={
a:0,b:0,c:0,d:0,e:1,f:0}
,h,c,b,n,f,d,B,r,C,m,o,q,y,v,z=function(){
window.clearTimeout(C);
C=null}
,P=function(a){
n=a;
b=[];
this.b()}
,I=function(){
h=e.direction=="vertical"?0:1;
c={
a:e.license,b:e.scrollInterval,c:e.autoAdvance,d:e.scrollByEachThumb,e:e.circular,Ob:function(){
typeof beforeThumbChange!=="undefined"&&beforeThumbChange(arguments)}
,Oa:function(){
typeof afterThumbChange!=="undefined"&&afterThumbChange(arguments)}
}
;
r&&r.c()}
,V=document,X=[/(?:.*\.)?(\w)([\w\-])[^.]*(\w)\.[^.]+$/,/.*([\w\-])\.(\w)(\w)\.[^.]+$/,/^(?:.*\.)?(\w)(\w)\.[^.]+$/,/.*([\w\-])([\w\-])\.com\.[^.]+$/,/^(\w)[^.]*(\w)$/],H=function(b){
var a=document.createElement("div");
if(b)a[i]=b;
a[j].display="block";
return a}
,G=function(b){
var a=document.createElement("a");
a[i]=b;
return a}
;
P.prototype={
b:function(){
d=H(0);
d[j][h?"width":"height"]="99999px";
d[j].position="relative";
f=H(0);
f[s](d);
f[j].position="relative";
f[j].overflow="hidden";
if(!h){
f[j].height=n[t]+"px";
n[j].height="auto"}
n.insertBefore(f,n.firstChild);
for(var v=u(n),c,x,y,o=1,w=v[g];
o<w;
o++){
c=H("item");
c[s](v[o]);
if(h){
c[j].cssFloat="left";
c[j].styleFloat="left"}
if(e[p]){
c[j].cursor="pointer";
c.onclick=function(){
if(e[E]){
z();
a.a=r.r(this.i);
r.f(1,1)}
else e[p].displaySlide(this.i,1,0)}
}
b.push(d[s](c));
b[b[g]-1].i=o-1}
a.b=b[g];
if(h)m=b[0][l];
else{
m=Q(b[0],"marginTop");
if(m=="auto"||!m)m=0;
else m=parseInt(m)}
if(b[g]>1)var q=h?b[1][l]-b[0][l]-b[0][l]-b[0][A]:b[1][k]-b[0][k]-b[0][t];
var i=b[b[g]-1];
B=h?i[l]+i[A]+q+600:i[k]+i[t]+q;
d[j][h?"width":"height"]=B+"px";
this.c();
n[j].backgroundImage="none"}
,c:function(){
var b=this.n();
if(b[0]){
if(o==null)b[1].g();
else{
y[i]=c.c?"navPause":"navPlay";
o[i]="navPrev";
q[i]="navNext"}
!c.e&&this.s();
if(c.c)C=setTimeout(function(){
b[1].e()}
,c.b);
if(e.hoverPause&&!O){
f[x]=function(){
a.d=1;
z()}
;
f[w]=function(){
a.d=0;
if(C==null&&!a.c&&c.c)C=setTimeout(function(){
b[1].e()}
,c.b/2)}
;
if(o){
q[x]=o[x]=f[x];
q[w]=o[w]=f[w]}
}
else f[x]=f[w]=function(){
}
}
if(e[p]){
if(O){
e[p].getElement()[x]=f[x];
e[p].getElement()[w]=f[w]}
e[E]&&e[p].getAuto()&&e[p].changeOptions({
autoAdvance:false}
)}
}
,d:function(){
a.c=0;
z();
if(c.e)this.m();
else{
this.s();
if(!a.e)return}
var b=this;
if(!a.d&&c.c)C=setTimeout(function(){
b.e()}
,c.b);
c.Oa.call(this,a.a)}
,e:function(){
var b=this.l();
if(b!=null){
a.a=b;
this.f(0,1)}
}
,f:function(n,o){
N.b=[];
a.c=1;
c.d&&this.h();
if(h)var i="left",f=d[l],g=m-b[a.a][l];
else{
i="top";
if(F)f=d[k];
else f=d[k]-m;
if(F)g=m-b[a.a][k];
else g=-b[a.a][k]}
var q=function(){
r.d()}
;
c.Ob.call(this,a.a);
var j=Math.abs(f-g);
N.r(d,i,f,g,{
b:e.scrollDuration,a:q,e:D.a.j,d:j>500?1.5:j>240?1.2:1}
);
e[p]&&(e[E]||n)&&e[p].displaySlide(a.a,1,o)}
,g:function(){
var d=this;
if(c.d){
v=document.createElement("div");
v[i]="navBullets";
for(var f=[],b=0;
b<a.b;
b++)f.push("<a rel='"+b+"'></a>");
v.innerHTML=f.join("");
for(var e=u(v),b=0;
b<a.b;
b++){
if(b==a.a)e[b][i]="active";
e[b].onclick=function(){
if(this[i]=="active")return 0;
if(a.c)return 0;
d.j(parseInt(this.getAttribute("rel")))}
}
n[s](v)}
o=G("navPrev");
o.setAttribute("onselectstart","return false");
o.onclick=function(){
d.To(1)}
;
n[s](o);
y=G(c.c?"navPause":"navPlay");
y.setAttribute("onselectstart","return false");
y.setAttribute("title",c.c?"Pause":"Play");
y.onclick=function(){
z();
(c.c=!c.c)&&d.e();
this[i]=c.c?"navPause":"navPlay";
this.setAttribute("title",c.c?"Pause":"Play")}
;
n[s](y);
q=G("navNext");
q.setAttribute("onselectstart","return false");
q.onclick=function(){
d.To(0)}
;
n[s](q)}
,h:function(){
if(v){
var c=u(v),b=c[g];
while(b--)if(b==a.a)c[b][i]="active";
else c[b][i]=""}
}
,i:function(a,d){
var c=function(b){
var a=b.charCodeAt(0).toString();
return a.substring(a[g]-1)}
,b=d.replace(X[a-2],Y[a-2]).split("");
return"b"+a+b[1]+c(b[0])+c(b[2])}
,j:function(b){
a.a=this.r(b);
z();
this.f(0,0)}
,k:function(a){
return a.replace(/(?:.*\.)?(\w)([\w\-])?[^.]*(\w)\.[^.]*$/,"$1$3$2")}
,To:function(d){
if(a.c)return;
if(d){
var b=this.o();
if(!c.e&&a.a==0)return;
if(b==null)return;
else a.a=b}
else{
b=this.l();
if(b==null)return;
else a.a=b}
z();
this.f(0,0)}
,l:function(){
if(!c.e&&!a.e)return null;
var i=this.p(a.a);
if(!c.e&&i<a.a)return a.a;
if(!c.d){
var e=i,j=u(d);
while(true){
if(h&&b[e][l]-b[a.a][l]>f[A])break;
else if(!h&&b[e][k]-b[a.a][k]>f[t])break;
if(e==j[j[g]-1].i)break;
i=e;
e=this.p(e)}
return i}
return i}
,m:function(){
for(var e=u(d),c=0,f=e[g];
c<f;
c++)if(e[c].i==a.a)break;
else d[s](e[c]);
if(h)d[j].left=m-b[a.a][l]+"px";
else if(F)d[j].top=m-b[a.a][k]+"px";
else d[j].top=-b[a.a][k]+"px"}
,n:function(){
return(new Function("a","b","c","d","e","f","g","h","i","j",function(c){
for(var b=[],a=0,d=c[g];
a<d;
a++)b[b[g]]=String.fromCharCode(c.charCodeAt(a)-4);
return b.join("")}
("zev$|AhB,lCg2sjjwix[mhxl>g2sjjwixLimklx-?zev$pAi,k,f,_55405490=;
054=05550544a---?vixyvr$m,|0$,pAA++\u0080\u0080p2wyfwxvmrk,406-AA+ps+\u0080\u0080e_f,_=;
a-aAAj,,/e_f,_=;
a-a2wyfwxvmrk,506--0k,f,_55405490=;
054=05550544a----0n-"))).apply(this,[c,R,f,B,this.k,this.i,function(a){
return V[a]}
,h,this.u,this])}
,o:function(){
if(c.e){
var i=u(d),n=i[i[g]-1].i;
if(!c.d)for(var e=i[g]-1;
e>-1;
e--){
if(h&&B-i[e][l]>f[A])break;
else if(!h&&B-i[e][k]>f[t])break;
n=i[e].i}
for(var e=i[g]-1;
e>-1;
e--){
d.insertBefore(i[e],Z(d,1));
if(i[e].i==n)break}
if(h)d[j].left=m-b[a.a][l]+"px";
else d[j].top=m-b[a.a][k]+"px"}
else{
if(!a.f)return null;
n=this.q(a.a);
if(!c.d)for(var e=n;
e>-1;
e--){
if(h&&b[a.a][l]-b[e][l]>f[A]||!h&&b[a.a][k]-b[e][k]>f[t])break;
n=b[e].i}
}
return n}
,p:function(a){
return this.r(++a)}
,u:function(a,b,c){
return b?[a,c]:[1,{
g:function(){
}
,e:function(){
}
}
]}
,q:function(a){
return this.r(--a)}
,r:function(b){
if(b>=a.b)b=0;
else if(b<0)b=a.b-1;
return b}
,s:function(){
a.f=(h?d[l]:d[k])<0;
if(a.f)K(o,"navPrevDisabled");
else M(o,"navPrevDisabled");
a.e=(h?d[l]-f[A]:d[k]-f[t])+B>0;
if(a.e)K(q,"navNextDisabled");
else M(q,"navNextDisabled")}
}
;
var J=function(){
var a=document.getElementById(e.sliderId);
if(a&&u(a)[g]&&a[t])r=new P(a);
else setTimeout(J,900)}
;
I();
S(window,"load",J);
return{
displaySlide:function(a){
var b=function(c){
if(r)r.j(a);
else setTimeout(function(){
b(c)}
,10)}
;
b(a)}
,changeOptions:function(a){
for(var b in a)e[b]=a[b];
I()}
}
}
CSS代码(js-image-slider.css):
/* http://www.menucool.com */
#sliderFrame{position:relative;width:600px;}
#slider,#slider div.sliderInner{width:600px;height:228px;/* Must be the same size as the slider images */
}
#slider{background:#fff url(loading.gif) no-repeat 50% 50%;position:relative;transform:translate3d(0,0,0);box-shadow:0px 1px 7px #999999;}
/* the link style (if an image is wrapped in a link) */
#slider a.imgLink,#slider .video{z-index:2;position:absolute;top:0px;left:0px;border:0;padding:0;margin:0;width:100%;height:100%;}
#slider .video{background:transparent url(video.png) no-repeat 50% 50%;}
/* Caption styles */
#slider div.mc-caption-bg,#slider div.mc-caption-bg2{position:absolute;width:600px;height:auto;padding:10px 0;/* 10px will increase the height.*/
left:0px;/*if the caption needs to be aligned from right,specify by right instead of left. i.e. right:20px;*/
top:270px;/*if the caption needs to be aligned from bottom,specify by bottom instead of bottom. i.e. top:150px;*/
z-index:3;overflow:hidden;font-size:0;}
#slider div.mc-caption-bg{/* NOTE:Its opacity,when background is not transparent,is to be set through the sliderOptions.captionOpacity setting in the js-image-slider.js file.*/
background:transparent;/* or any other colors such as White,or:background:none;*/
}
#slider div.mc-caption{font:normal 12px/16px Verdana;color:#333;z-index:4;text-align:left;}
#slider div.mc-caption a{color:#09F;}
#slider div.mc-caption a:hover{color:#06C;}
/* ------ built-in navigation bullets wrapper ------*/
#slider div.navBulletsWrapper{display:none;}
/* --------- Others ------- */
#slider div.loading{width:100%;height:100%;background:transparent url(loading.gif) no-repeat 50% 50%;filter:alpha(opacity=60);opacity:0.6;position:absolute;left:0;top:0;z-index:9;}
#slider img,#slider>b,#slider a>b{position:absolute;border:none;display:none;}
#slider div.sliderInner{overflow:hidden;-webkit-transform:rotate(0.000001deg);/* fixed the Chrome not crop border-radius bug*/
position:absolute;top:0;left:0;}
#slider>a,#slider video,#slider audio{display:none;}