以下是 百度翻译手机版jQuery焦点图轮播滚动切换特效代码 的示例演示效果:
部分效果截图:
HTML代码(index.html):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<!--[if IE 6]>
<script type="text/javascript" src="js/DD_belatedPNG.js"></script>
<script type="text/javascript">DD_belatedPNG.fix(".other_download,.title,.2d_code");</script>
<![endif]-->
<title>百度翻译手机版jQuery焦点图</title>
<link rel="stylesheet" href="css/zzsc.css" />
</head>
<body>
<div id="main" class="relative">
<div id="slide" class="slide_wrap">
<ul class="slide_imglist conbox">
<li class="i1">
<img alt="" src="imgs/i1.jpg"></li>
<li class="i2">
<img alt="" src="imgs/i2.jpg"></li>
<li class="i3">
<img alt="" src="imgs/i3.jpg"></li>
<li class="i4">
<img alt="" src="imgs/i4.jpg"></li>
</ul>
<div class="switcher">
<a href="#" class="cur"></a>
<a href="#"></a>
<a href="#"></a>
<a href="#"></a>
</div>
<!-- <div class="slide_title_bg"></div>
-->
</div>
<div class="download_box absolute">
<div class="download_inner relative">
<h1 class="title"></h1>
<div class="down_left relative">
<a class="andriod_download" href="#" title="下载Android版"></a>
<a class="iphone_download" href="#" title="下载iOS版" target="_blank"></a>
<br class="clr_fix"/>
</div>
<div class="down_right relative">
<div class="2d_code" style="margin-top:12px;display:inline-block;width:118px;height:118px;background:url(imgs/synthesis.png) no-repeat scroll 0 -427px transparent;"></div>
<div class="code_desc">扫描二维码 直接下载</div>
</div>
<div class="other_download absolute">
<div class="front">
其他下载方式
<span id="dropdown"></span>
<div class="other_links SimSun">
<a class="wdy" style="margin-left:2px;" href="#" name="百度翻译" onclick="return wdapi_apkdl_m(this, 'source');" target="_blank" title="豌豆荚">豌豆荚</a>
<a class="zs91" href="#" name="百度翻译" onclick="return Key.Open(this, 'Android');" target="_blank" title="91助手">91助手</a>
<a class="googlePlay" href="#" target="_blank" title="Google play">Google play</a>
<a class="android" href="#" target="_blank" title="安卓市场">安卓市场</a>
<a class="yyh" href="#l" target="_blank" title="应用汇">应用汇</a>
<a class="yyb" href="#" target="_blank" title="应用宝">应用宝</a>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="js/jquery-1.10.1.min.js"></script>
<script src="js/jquery.Xslider.js"></script>
<script>
// 焦点图片淡隐淡现
$("#slide").Xslider({
affect:'fade',
ctag: 'li', //内容标签 默认为<a>
speed: 800, //动画速度
space: 6000, //时间间隔
auto: true, //自动滚动
trigger: 'mouseover', //触发事件 注意用mouseover代替hover
conbox: '.conbox', //内容容器id或class
switcher: '.switcher', //切换触发器id或class
stag: 'a', //切换器标签 默认为a
current:'cur', //当前切换器样式名称
rand:false //是否随机指定默认幻灯图片
});
//统计代码
$(document).delegate('a', 'click', function(ev) {
var target = ev.target, $target = $(target);
var action, info, url;
info = encodeURIComponent($target.attr('title'));
url = encodeURIComponent($target.attr('href'));
});
</script>
<br><br>
</body>
</html>
JS代码(DD_belatedPNG.js):
var DD_belatedPNG ={
ns:"DD_belatedPNG",imgSize:{
}
,delay:10,nodesFixed:0,createVmlNameSpace:function(){
if (document.namespaces && !document.namespaces[this.ns]){
document.namespaces.add(this.ns,"urn:schemas-microsoft-com:vml")}
}
,createVmlStyleSheet:function(){
var c,d;
c = document.createElement("style");
c.setAttribute("media","screen");
document.documentElement.firstChild.insertBefore(c,document.documentElement.firstChild.firstChild);
if (c.styleSheet){
c = c.styleSheet;
c.addRule(this.ns + "\\:*","{
behavior:url(#default#VML)}
");
c.addRule(this.ns + "\\:shape","position:absolute;
");
c.addRule("img." + this.ns + "_sizeFinder","behavior:none;
border:none;
position:absolute;
z-index:-1;
top:-10000px;
visibility:hidden;
");
this.screenStyleSheet = c;
d = document.createElement("style");
d.setAttribute("media","print");
document.documentElement.firstChild.insertBefore(d,document.documentElement.firstChild.firstChild);
d = d.styleSheet;
d.addRule(this.ns + "\\:*","{
display:none !important;
}
");
d.addRule("img." + this.ns + "_sizeFinder","{
display:none !important;
}
")}
}
,readPropertyChange:function(){
var d,f,e;
d = event.srcElement;
if (!d.vmlInitiated){
return}
if (event.propertyName.search("background") != -1|| event.propertyName.search("border") != -1){
DD_belatedPNG.applyVML(d)}
if (event.propertyName == "style.display"){
f = (d.currentStyle.display == "none") ? "none":"block";
for (e in d.vml){
if (d.vml.hasOwnProperty(e)){
d.vml[e].shape.style.display = f}
}
}
if (event.propertyName.search("filter") != -1){
DD_belatedPNG.vmlOpacity(d)}
}
,vmlOpacity:function(c){
if (c.currentStyle.filter.search("lpha") != -1){
var d = c.currentStyle.filter;
d = parseInt(d.substring(d.lastIndexOf("=") + 1,d.lastIndexOf(")")),10)/ 100;
c.vml.color.shape.style.filter = c.currentStyle.filter;
c.vml.image.fill.opacity = d}
}
,handlePseudoHover:function(b){
setTimeout(function(){
DD_belatedPNG.applyVML(b)}
,1)}
,fix:function(e){
if (this.screenStyleSheet){
var f,d;
f = e.split(",");
for (d = 0;
d < f.length;
d++){
this.screenStyleSheet.addRule(f[d],"behavior:expression(DD_belatedPNG.fixPng(this))")}
}
}
,applyVML:function(b){
b.runtimeStyle.cssText = "";
this.vmlFill(b);
this.vmlOffsets(b);
this.vmlOpacity(b);
if (b.isImg){
this.copyImageBorders(b)}
}
,attachHandlers:function(h){
var m,n,j,l,a,k;
m = this;
n ={
resize:"vmlOffsets",move:"vmlOffsets"}
;
if (h.nodeName == "A"){
l ={
mouseleave:"handlePseudoHover",mouseenter:"handlePseudoHover",focus:"handlePseudoHover",blur:"handlePseudoHover"}
;
for (a in l){
if (l.hasOwnProperty(a)){
n[a] = l[a]}
}
}
for (k in n){
if (n.hasOwnProperty(k)){
j = function(){
m[n[k]](h)}
;
h.attachEvent("on" + k,j)}
}
h.attachEvent("onpropertychange",this.readPropertyChange)}
,giveLayout:function(b){
b.style.zoom = 1;
if (b.currentStyle.position == "static"){
b.style.position = "relative"}
}
,copyImageBorders:function(d){
var f,e;
f ={
borderStyle:true,borderWidth:true,borderColor:true}
;
for (e in f){
if (f.hasOwnProperty(e)){
d.vml.color.shape.style[e] = d.currentStyle[e]}
}
}
,vmlFill:function(l){
if (!l.currentStyle){
return}
else{
var m,k,j,h,i,n;
m = l.currentStyle}
for (h in l.vml){
if (l.vml.hasOwnProperty(h)){
l.vml[h].shape.style.zIndex = m.zIndex}
}
l.runtimeStyle.backgroundColor = "";
l.runtimeStyle.backgroundImage = "";
k = true;
if (m.backgroundImage != "none" || l.isImg){
if (!l.isImg){
l.vmlBg = m.backgroundImage;
l.vmlBg = l.vmlBg.substr(5,l.vmlBg.lastIndexOf('")') - 5)}
else{
l.vmlBg = l.src}
j = this;
if (!j.imgSize[l.vmlBg]){
i = document.createElement("img");
j.imgSize[l.vmlBg] = i;
i.className = j.ns + "_sizeFinder";
i.runtimeStyle.cssText = "behavior:none;
position:absolute;
left:-10000px;
top:-10000px;
border:none;
margin:0;
padding:0;
";
n = function(){
this.width = this.offsetWidth;
this.height = this.offsetHeight;
j.vmlOffsets(l)}
;
i.attachEvent("onload",n);
i.src = l.vmlBg;
i.removeAttribute("width");
i.removeAttribute("height");
document.body.insertBefore(i,document.body.firstChild)}
l.vml.image.fill.src = l.vmlBg;
k = false}
l.vml.image.fill.on = !k;
l.vml.image.fill.color = "none";
l.vml.color.shape.style.backgroundColor = m.backgroundColor;
l.runtimeStyle.backgroundImage = "none";
l.runtimeStyle.backgroundColor = "transparent"}
,vmlOffsets:function(x){
var t,b,y,w,u,c,v,o,q,s,p;
t = x.currentStyle;
b ={
W:x.clientWidth + 1,H:x.clientHeight + 1,w:this.imgSize[x.vmlBg].width,h:this.imgSize[x.vmlBg].height,L:x.offsetLeft,T:x.offsetTop,bLW:x.clientLeft,bTW:x.clientTop}
;
y = (b.L + b.bLW == 1) ? 1:0;
w = function(a,g,f,h,e,d){
a.coordsize = h + "," + e;
a.coordorigin = d + "," + d;
a.path = "m0,0l" + h + ",0l" + h + "," + e + "l0," + e + " xe";
a.style.width = h + "px";
a.style.height = e + "px";
a.style.left = g + "px";
a.style.top = f + "px"}
;
w(x.vml.color.shape,(b.L + (x.isImg ? 0:b.bLW)),(b.T + (x.isImg? 0:b.bTW)),(b.W - 1),(b.H - 1),0);
w(x.vml.image.shape,(b.L + b.bLW),(b.T + b.bTW),(b.W),(b.H),1);
u ={
X:0,Y:0}
;
if (x.isImg){
u.X = parseInt(t.paddingLeft,10) + 1;
u.Y = parseInt(t.paddingTop,10) + 1}
else{
for (q in u){
if (u.hasOwnProperty(q)){
this.figurePercentage(u,b,q,t["backgroundPosition" + q])}
}
}
x.vml.image.fill.position = (u.X / b.W) + "," + (u.Y / b.H);
c = t.backgroundRepeat;
v ={
T:1,R:b.W + y,B:b.H,L:1 + y}
;
o ={
X:{
b1:"L",b2:"R",d:"W"}
,Y:{
b1:"T",b2:"B",d:"H"}
}
;
if (c != "repeat" || x.isImg){
s ={
T:(u.Y),R:(u.X + b.w),B:(u.Y + b.h),L:(u.X)}
;
if (c.search("repeat-") != -1){
p = c.split("repeat-")[1].toUpperCase();
s[o[p].b1] = 1;
s[o[p].b2] = b[o[p].d]}
if (s.B > b.H){
s.B = b.H}
x.vml.image.shape.style.clip = "rect(" + s.T + "px " + (s.R + y)+ "px " + s.B + "px " + (s.L + y) + "px)"}
else{
x.vml.image.shape.style.clip = "rect(" + v.T + "px " + v.R + "px "+ v.B + "px " + v.L + "px)"}
}
,figurePercentage:function(k,l,i,h){
var g,j;
j = true;
g = (i == "X");
switch (h){
case "left":case "top":k[i] = 0;
break;
case "center":k[i] = 0.5;
break;
case "right":case "bottom":k[i] = 1;
break;
default:if (h.search("%") != -1){
k[i] = parseInt(h,10) / 100}
else{
j = false}
}
k[i] = Math.ceil(j? ((l[g ? "W":"H"] * k[i]) - (l[g ? "w":"h"] * k[i])):parseInt(h,10));
if (k[i] % 2 === 0){
k[i]++}
return k[i]}
,fixPng:function(l){
l.style.behavior = "none";
var i,e,j,h,k;
if (l.nodeName == "BODY" || l.nodeName == "TD" || l.nodeName == "TR"){
return}
l.isImg = false;
if (l.nodeName == "IMG"){
if (l.src.toLowerCase().search(/\.png$/) != -1){
l.isImg = true;
l.style.visibility = "hidden"}
else{
return}
}
else{
if (l.currentStyle.backgroundImage.toLowerCase().search(".png") == -1){
return}
}
i = DD_belatedPNG;
l.vml ={
color:{
}
,image:{
}
}
;
e ={
shape:{
}
,fill:{
}
}
;
for (h in l.vml){
if (l.vml.hasOwnProperty(h)){
for (k in e){
if (e.hasOwnProperty(k)){
j = i.ns + ":" + k;
l.vml[h][k] = document.createElement(j)}
}
l.vml[h].shape.stroked = false;
l.vml[h].shape.appendChild(l.vml[h].fill);
l.parentNode.insertBefore(l.vml[h].shape,l)}
}
l.vml.image.shape.fillcolor = "none";
l.vml.image.fill.type = "tile";
l.vml.color.fill.on = false;
i.attachHandlers(l);
i.giveLayout(l);
i.giveLayout(l.offsetParent);
l.vmlInitiated = true;
i.applyVML(l)}
}
;
try{
document.execCommand("BackgroundImageCache",false,true)}
catch (r){
}
DD_belatedPNG.createVmlNameSpace();
DD_belatedPNG.createVmlStyleSheet();
JS代码(jquery.Xslider.js):
/** * @package Xslider - A slider plugin for jQuery * @version 0.5 * @author xhowhy <http://x1989.com> **/
;
(function($){
$.fn.Xslider = function(options){
var settings ={
affect:'scrollx',//效果 有scrollx|scrolly|fade|nonespeed:1200,//动画速度space:4000,//时间间隔auto:true,//自动滚动trigger:'mouseover',//触发事件 注意用mouseover代替hoverconbox:'.conbox',//内容容器id或classctag:'a',//内容标签 默认为<a>switcher:'.switcher',//切换触发器id或classstag:'a',//切换器标签 默认为acurrent:'cur',//当前切换器样式名称rand:false //是否随机指定默认幻灯图片}
;
settings = $.extend({
}
,settings,options);
var index = 1;
var last_index = 0;
var $conbox = $(this).find(settings.conbox),$contents = $conbox.find(settings.ctag);
var $switcher = $(this).find(settings.switcher),$stag = $switcher.find(settings.stag);
if(settings.rand){
index = Math.floor(Math.random()*$contents.length);
slide();
}
if(settings.affect == 'fade'){
$.each($contents,function(k,v){
(k === 0) ? $(this).css({
'position':'absolute','z-index':9}
):$(this).css({
'position':'absolute','z-index':1,'opacity':0}
);
}
);
}
function slide(){
if (index >= $contents.length) index = 0;
$stag.removeClass(settings.current).eq(index).addClass(settings.current);
switch(settings.affect){
case 'scrollx':$conbox.width($contents.length*$contents.width());
$conbox.stop().animate({
left:-$contents.width()*index}
,settings.speed);
break;
case 'scrolly':$contents.css({
display:'block'}
);
$conbox.stop().animate({
top:-$contents.height()*index+'px'}
,settings.speed);
break;
case 'fade':$contents.eq(last_index).stop().animate({
'opacity':0}
,settings.speed/2).css('z-index',1) .end() .eq(index).css('z-index',9).stop().animate({
'opacity':1}
,settings.speed/2)break;
case 'none':$contents.hide().eq(index).show();
break;
}
last_index = index;
index++;
}
;
if(settings.auto) var Timer = setInterval(slide,settings.space);
$stag.bind(settings.trigger,function(){
_pause()index = $(this).index();
slide();
_continue()}
);
$conbox.hover(_pause,_continue);
function _pause(){
clearInterval(Timer);
}
function _continue(){
if(settings.auto)Timer = setInterval(slide,settings.space);
}
}
}
)(jQuery);
CSS代码(zzsc.css):
/*_reset.css*/
html,body,h1,h2,h3,h4,h5,h6,p,ul,ol,li,dl,dt,dd,th,td,form,fieldset,legend,input,textarea,blockquote,address,pre{margin:0;padding:0}
table{border-collapse:collapse;border-spacing:0}
img,fieldset,hr,iframe{border:0}
img,.img{display:inline-block;vertical-align:top}
a,del,ins{text-decoration:none}
li{list-style:none}
q:before,q:after{content:''}
sup,sub{vertical-align:baseline}
body,input,textarea,select{font:normal 12px/1.667 Microsoft YaHei,Arial,Tahoma;color:#666}
h1,h2,h3,h4,h5,h6,b{font-size:1em;font-weight:normal}
textarea{line-height:1.5;max-height:348px;resize:vertical!important}
i,cite,em,var,dfn,address{font-style:normal}
a{text-decoration:none;outline:0!important;color:#969696}
a:hover,.underline{text-decoration:underline}
a,label{cursor:pointer}
.red,.red a{color:#d50000;}
.gray,.gray a{color:#a4a4a4;}
.orange,.orange a{color:#ec8a15;}
.green,.green a{color:#94b316;}
.blue,.blue a{color:#346ec5;}
.mt10{margin-top:10px;}
.mt20{margin-top:20px;}
.fwb{font-weight:bold;}
.taR{text-align:right;}
.fl{float:left;display:inline;}
.fr{float:right;display:inline;}
body{font:12px Microsoft YaHei,Arial,Tahoma;}
.Yahei{font-family:Microsoft YaHei;}
.SimSun{font-family:SimSun}
.relative{position:relative;}
.absolute{position:absolute;}
.clr_fix{clear:both;}
.clearfix:after{content:".";height:0;visibility:hidden;display:block;clear:both;}
.slide{height:596px;}
.slide_imglist{height:541px;}
/* .slide ul li img{background:url("../imgs/i1.png") no-repeat scroll 50% 0 transparent;}
*/
.slide_title{height:55px;width:100%;overflow:hidden;}
.fn_area{position:relative;height:365px;background:none repeat scroll 0 0 #FFFFFF;}
.fn_area_inner{width:1000px;margin:0 auto;}
.fn_area_inner ul li{width:315px;float:left;position:relative;margin:68px 16px 0 0;display:inline;}
.li_logo{float:left;width:80px;height:80px;}
.li_cnt{float:left;width:210px;margin:4px 0 0 15px;}
.li_logo,.header_logo,.cell_asis,.voice_asis,.browser,.typewriting,.add_notice,.mail_to,.header_logo{background:url("../imgs/synthesis.png") no-repeat scroll 0 0 transparent;_background-image:url(../imgs/synthesis_ie6.png);}
.cnt_title{font-size:22.15px;}
.cnt_desc{color:#777777;padding-top:10px;}
.offline_translation{background-position:0 -155px;}
.voice_input{background-position:0 -243px;}
.conditioning_words{background-position:-163px -155px;}
.carma_input{background-position:0 -333px;}
.rich_dict{background-position:-163px -243px}
.software_translation{background-position:-163px -333px}
.essence{background-color:#e6e8ea;}
.links{width:1000px;height:315px;margin:0 auto;}
.essence_title{color:#666;font:18px Microsoft YaHei,Arial,Tahoma;padding-top:52px;text-indent:6px;}
.essence_anchor{height:78px;margin-top:48px;padding:0 1px;}
.essence_anchor a{margin:0 0 0 -1px;border:1px solid #d0d2d4;border-left:1px solid #d0d2d4;display:inline-block;float:left;font:14px Microsoft YaHei;margin-right:0;/*text-indent:4em;*/
width:248px;background-color:#EDEFF1;text-decoration:none;color:#7f8080;vertical-align:middle;height:78px;}
.essence_anchor a span{line-height:78px;margin-right:6px;float:left;}
.cell_asis{height:45px;width:47px;background-position:0 -565px;}
.voice_asis{width:47px;height:46px;background-position:-71px -565px;}
.browser{width:45px;height:49px;background-position:-198px -562px}
.typewriting{width:47px;height:42px;background-position:-139px -568px}
.footer{height:141px;background-color:#4f5358;color:#bbbbbb;}
.contact_us{height:70px;line-height:70px;margin:0 auto;text-align:center;width:376px;}
.contact_us span{float:left;}
.legal{margin:0 auto;text-align:center;width:1000px;height:50px;line-height:50px;}
.add_notice{background-position:0 -668px;display:inline;height:22px;margin:24px 20px 0 10px;vertical-align:middle;width:69px;cursor:pointer;}
.mail_to{background-position:-223px -668px;display:inline;height:15px;margin-right:5px;margin-top:28px;text-indent:6px;vertical-align:middle;width:20px;}
.email{color:#ffffff;}
.gap{padding:0 8px;font-style:normal;}
.gap a{text-decoration:none;color:#bbb;}
.link_wrap{display:block;height:45px;line-height:45px;margin:16px auto 0;width:145px;}
.header{width:100%;height:66px;top:0;left:0;background:url("../imgs/header.png") repeat scroll 0 0 transparent;z-index:9;}
.header_inner{margin:0 auto;width:980px;height:66px;line-height:66px;z-index:10;}
.header_logo{background-position:0 -619px;/* display:inline-block;*/
height:39px;top:13px;width:39px;}
.header_desc{color:#FFFFFF;font-size:30px;left:46px;top:-2px;}
.slide_wrap{overflow:hidden;margin-bottom:0;position:relative;width:100%;}
.slide_imglist li{position:absolute;display:inline;background:#3475D1;width:100%;text-align:center;opacity:0;/*margin-right:3px;*/
}
.slide_imglist .i1{opacity:1;z-index:9;}
.slide_imglist .i2{background:#E29C39;z-index:1;}
.slide_imglist .i3{background:#BF3451;z-index:1;}
.slide_imglist .i4{background:#6C19B2;z-index:1;}
.switcher{overflow:hidden;margin:0 auto;margin-top:20px;width:134px;}
.switcher a{overflow:hidden;margin-right:20px;background-color:#d9d9d9;cursor:pointer;display:inline;float:left;font-size:12px;font-weight:bold;height:12px;line-height:12px;text-align:center;width:12px;border-radius:100%;}
.switcher .cur{background-color:#3475d1;}
.download_box{width:100%;top:278px;z-index:10;}
.download_inner{margin:0 auto;width:1000px;height:253px;}
.down_left{display:inline;float:left;height:165px;margin-left:611px;width:243px;}
.down_right{display:inline;float:right;height:156px;margin-right:11px;width:118px;}
.andriod_download{margin-bottom:14px;display:inline-block;width:243px;height:75px;background:url("../imgs/synthesis.png") no-repeat 0 -75px;_background-image:url(../imgs/synthesis_ie6.png);}
.iphone_download{display:inline-block;width:243px;height:75px;background:url("../imgs/synthesis.png") no-repeat scroll 0 0 transparent;_background-image:url(../imgs/synthesis_ie6.png);}
.code_desc{margin-top:15px;color:#dddddd;text-align:center;}
.other_download{background-image:url("../imgs/dropdown.png");border-radius:3px 3px 3px 3px;bottom:10px;height:60px;right:10px;width:380px;}
.front{color:#FFFFFF;height:60px;text-indent:1em;width:380px;padding-top:5px;font-size:14px;}
.front #dropdown{background:url("../imgs/synthesis.png") no-repeat scroll -236px -426px transparent;display:inline-block;height:5px;margin-left:5px;vertical-align:middle;width:8px;_background-image:url(../imgs/synthesis_ie6.png);}
.other_links{font-size:12px;margin-top:12px;}
.other_links a{color:#FFFFFF;margin-right:12px;}
.header,.download_box,.slide,.slide_title,.fn_area,.essence,.footer{min-width:1000px;}
.title{position:absolute;top:-152px;right:5px;width:386px;height:109px;background:url(../imgs/bg_title.png) no-repeat;}