以下是 简洁的左右切换焦点图代码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" />
<meta name="keywords" content="JS代码,焦点图,JS广告代码,JS特效代码" />
<meta name="description" content="此代码内容为简洁的左右切换焦点图代码(jQuery)" />
<title>简洁的左右切换焦点图代码(jQuery)</title>
<link href="css/simplefoucs_lrtk.css" rel="stylesheet" />
<script src="js/jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="js/simplefoucs.js" type="text/javascript"></script>
</head>
<body>
<!-- 代码 开始 -->
<div class="bannerbox">
<div id="focus">
<ul>
<li><a href="#" target="_blank">
<img src="images/bn1.jpg" alt="" /></a></li>
<li><a href="#" target="_blank">
<img src="images/bn2.jpg" alt="" /></a></li>
<li><a href="#" target="_blank">
<img src="images/bn3.jpg" alt="" /></a></li>
<li><a href="#" target="_blank">
<img src="images/bn4.jpg" alt="" /></a></li>
</ul>
</div>
</div>
</body>
</html>
JS代码(simplefoucs.js):
$(function (){
var sWidth = $("#focus").width();
var len = $("#focus ul li").length;
var index = 0;
var picTimer;
var btn = "<div class='btnBg'></div><div class='btn'>";
for (var i = 0;
i < len;
i++){
btn += "<span></span>";
}
btn += "</div><div class='preNext pre'></div><div class='preNext next'></div>";
$("#focus").append(btn);
$("#focus .btnBg").css("opacity",0);
$("#focus .btn span").css("opacity",0.4).mouseenter(function (){
index = $("#focus .btn span").index(this);
showPics(index);
}
).eq(0).trigger("mouseenter");
$("#focus .preNext").css("opacity",0.0).hover(function (){
$(this).stop(true,false).animate({
"opacity":"0.5"}
,300);
}
,function (){
$(this).stop(true,false).animate({
"opacity":"0"}
,300);
}
);
$("#focus .pre").click(function (){
index -= 1;
if (index == -1){
index = len - 1;
}
showPics(index);
}
);
$("#focus .next").click(function (){
index += 1;
if (index == len){
index = 0;
}
showPics(index);
}
);
$("#focus ul").css("width",sWidth * (len));
$("#focus").hover(function (){
clearInterval(picTimer);
}
,function (){
picTimer = setInterval(function (){
showPics(index);
index++;
if (index == len){
index = 0;
}
}
,2800);
}
).trigger("mouseleave");
function showPics(index){
var nowLeft = -index * sWidth;
$("#focus ul").stop(true,false).animate({
"left":nowLeft}
,300);
$("#focus .btn span").stop(true,false).animate({
"opacity":"0.4"}
,300).eq(index).stop(true,false).animate({
"opacity":"1"}
,300);
}
}
);
CSS代码(simplefoucs_lrtk.css):
@charset "utf-8";img{border:0px;}
.bannerbox{width:1172px;height:447px;overflow:hidden;margin:0px auto;}
#focus{width:1172px;height:447px;clear:both;overflow:hidden;position:relative;float:left;}
#focus ul{width:1172px;height:447px;float:left;position:absolute;clear:both;padding:0px;margin:0px;}
#focus ul li{float:left;width:1172px;height:447px;overflow:hidden;position:relative;padding:0px;margin:0px;}
#focus .preNext{width:550px;height:447px;position:absolute;top:0px;cursor:pointer;}
#focus .pre{left:0;background:url(../images/sprite.png) no-repeat left center;}
#focus .next{right:0;background:url(../images/sprite1.png) no-repeat right center;}