jquery高仿2012淘宝商城多格子焦点图滚动切换

原文地址:http://www.jsfoot.com/jquery/images/qh/2012-10-30/787.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=utf-8" />
<title>jquery高仿2012淘宝商城多格子焦点图滚动切换</title>
<meta name="description" content="jquery图片滚动切换特效,高仿2012淘宝商城首页多格子焦点图切换,鼠标滑过焦点图片各个格子区域聚光灯效果展示。且带索引序号按钮控制图片对应的格子切换滚动效果。" />


<style type="text/css">
*{margin:0;padding:0;list-style-type:none;}
/*全局声明!就是说这个网页中所有的元素的外边距和内边距都为0, 项目列表前的类型为无,也就是隐藏!一般项目列表默认的前面都有个小黑点的,这个代码就能隐藏那个小点*/
body{font:12px/180% Arial, Helvetica, sans-serif, "宋体";color:#333;background:#f0f0f0;}
a,img{border:0;}
/* demo */
.demo{width:780px;margin:0 auto;}
.demo h2{height:70px;line-height:50px;font-size:22px;font-weight:normal;font-family:"Microsoft YaHei",SimHei;text-align:center;}
/* focus */
#focus{position:relative;width:780px;height:420px;overflow:hidden;}
#focus ul{height:420px;position:absolute;}
#focus ul li{float:left;width:780px;height:420px;overflow:hidden;position:relative;background:#000;}
#focus ul li div{position:absolute;overflow:hidden;}
#focus .btnBg{position:absolute;width:780px;height:40px;left:0;bottom:0;background:#000;}
#focus .btn{position:absolute;height:30px;left:10px;bottom:4px;}
#focus .btn span{
 float:left;display:inline-block;width:30px;height:30px;line-height:30px;text-align:center;font-size:16px;margin-right:10px;cursor:pointer;background:#716564;color:#ffffff;
 border-radius:15px;
 -moz-border-radius:15px;
 -webkit-border-radius:15px;
}
#focus .btn span.on{background:#B91919;color:#ffffff;}
</style>

<script type="text/javascript" src="http://www.jsfoot.com/skin/js/jquery.js"></script>
<script type="text/javascript">
$(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>" + (i+1) + "</span>";
 }
 btn += "</div>"
 $("#focus").append(btn);
 $("#focus .btnBg").css("opacity",0.3);

 //为数字按钮添加鼠标滑入事件,以显示相应的内容
 $("#focus .btn span").mouseenter(function(){
  index = $("#focus .btn span").index(this);
  showPics(index);
 }).eq(0).trigger("mouseenter");

 //本例为左右滚动,即所有li元素都是在同一排向左浮动,所以这里需要计算出外围ul元素的宽度
 $("#focus ul").css("width",sWidth * (len + 1));

 //鼠标滑入某li中的某div里,调整其同辈div元素的透明度,由于li的背景为黑色,所以会有变暗的效果
 $("#focus ul li div").hover(function(){
  $(this).siblings().css("opacity",0.7);
 },function() {
  $("#focus ul li div").css("opacity",1);
 });

 //鼠标滑上焦点图时停止自动播放,滑出时开始自动播放
 $("#focus").hover(function(){
  clearInterval(picTimer);
 },function(){
  picTimer = setInterval(function(){
   if(index == len){ //如果索引值等于li元素个数,说明最后一张图播放完毕,接下来要显示第一张图,即调用showFirPic(),然后将索引值清零
    showFirPic();
    index = 0;
   }else{ //如果索引值不等于li元素个数,按普通状态切换,调用showPics()
    showPics(index);
   }
   index++;
  },3000); //此3000代表自动播放的间隔,单位:毫秒
 }).trigger("mouseleave");

 //显示图片函数,根据接收的index值显示相应的内容
 function showPics(index){  //普通切换
  var nowLeft = -index*sWidth; //根据index值计算ul元素的left值
  $("#focus ul").stop(true,false).animate({"left":nowLeft},500); //通过animate()调整ul元素滚动到计算出的position
  $("#focus .btn span").removeClass("on").eq(index).addClass("on"); //为当前的按钮切换到选中的效果
 }

 function showFirPic(){ //最后一张图自动切换到第一张图时专用
  $("#focus ul").append($("#focus ul li:first").clone());
  var nowLeft = -len*sWidth; //通过li元素个数计算ul元素的left值,也就是最后一个li元素的右边
  $("#focus ul").stop(true,false).animate({"left":nowLeft},500,function(){
   //通过callback,在动画结束后把ul元素重新定位到起点,然后删除最后一个复制过去的元素
   $("#focus ul").css("left","0");
   $("#focus ul li:last").remove();
  });
  $("#focus .btn span").removeClass("on").eq(0).addClass("on"); //为第一个按钮添加选中的效果
 }
 
});
</script>
</head>

<body>


<div class="demo">
 <h2>jquery高仿2012淘宝商城多格焦点图滚动切换</h2>
 <div id="focus">
  <ul>
   <li>
    <div style="left:0;top:0;"><a href="http://www.jsfoot.com/"><img width="780" height="420" src="images/5364.jpg" alt="2012淘宝商城最新多格焦点图源代码" /></a></div>
    
   </li>
   <li>
    <div style="left:0;top:0;"><a href="http://www.jsfoot.com/"><img width="560" height="420" src="images/5152.jpg" alt="2012淘宝商城最新多格焦点图源代码" /></a></div>
    <div style="right:0;top:0;"><a href="http://www.jsfoot.com/"><img width="220" height="140" src="images/234rwe.jpg" alt="2012淘宝商城最新多格焦点图源代码" /></a></div>
    <div style="right:0;top:140px;"><a href="http://www.jsfoot.com/"><img width="220" height="140" src="images/54325.jpg" alt="2012淘宝商城最新多格焦点图源代码" /></a></div>
    <div style="right:0;bottom:0;"><a href="http://www.jsfoot.com/"><img width="220" height="140" src="images/as124.jpg" alt="2012淘宝商城最新多格焦点图源代码" /></a></div>
   </li>
   <li>
    <div style="left:0;top:0;"><a href="http://www.jsfoot.com/"><img width="260" height="210" src="images/12as.jpg" alt="2012淘宝商城最新多格焦点图源代码" /></a></div>
    <div style="left:260px;top:0;"><a href="http://www.jsfoot.com/"><img width="260" height="210" src="images/12wf.jpg" alt="2012淘宝商城最新多格焦点图源代码" /></a></div>
    <div style="left:0;top:210px;"><a href="http://www.jsfoot.com/"><img width="520" height="210" src="images/adf13.jpg" alt="2012淘宝商城最新多格焦点图源代码" /></a></div>
    <div style="right:0;top:0;"><a href="http://www.jsfoot.com/"><img width="260" height="420" src="images/1235.jpg" alt="2012淘宝商城最新多格焦点图源代码" /></a></div>
   </li>
   <li>
    <div style="left:0;top:0;"><a href="http://www.jsfoot.com/"><img width="560" height="420" src="images/5243.jpg" alt="2012淘宝商城最新多格焦点图源代码" /></a></div>
    <div style="right:0;top:0;"><a href="http://www.jsfoot.com/"><img width="220" height="140" src="images/3246.jpg" alt="2012淘宝商城最新多格焦点图源代码" /></a></div>
    <div style="right:0;top:140px;"><a href="http://www.jsfoot.com/"><img width="220" height="140" src="images/536.jpg" alt="2012淘宝商城最新多格焦点图源代码" /></a></div>
    <div style="right:0;bottom:0;"><a href="http://www.jsfoot.com/"><img width="220" height="140" src="images/56dsfa.jpg" alt="2012淘宝商城最新多格焦点图源代码" /></a></div>
   </li>
   <li>
    <div style="left:0;top:0;"><a href="http://www.jsfoot.com/"><img width="780" height="420" src="images/52525.jpg" alt="2012淘宝商城最新多格焦点图源代码" /></a></div>
   </li>
  </ul>
 </div>
</div>
 
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值