jquery版仿淘宝商城天猫首页多格焦点图效果

效果图:

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">
<meta name="Copyright" content="W3Cfuns/" />
<title>仿天猫轮播</title>
<style type="text/css">
* {margin:0; padding:0;}
body {font-size:12px; color:#222; font-family:Verdana,Arial,Helvetica,sans-serif; background:#f0f0f0;}
.clearfix:after {content: "."; display: block; height: 0; clear: both; visibility: hidden;}
.clearfix {zoom:1;}
ul,li {list-style:none;}
img {border:0;}

.wrapper {width:600px; margin:0 auto; padding-bottom:30px;}
.ad {width:468px; margin:10px auto 0;}
.ad li {padding-top:5px;}

h1 {height:50px; line-height:50px; font-size:22px; font-weight:normal; font-family:"Microsoft YaHei",SimHei;}

.download {display:block; width:120px; height:34px; background:#333; line-height:34px; font-size:14px; font-weight:bold; text-align:center; color:#fff; border:1px solid #999;}

.shuoming {margin-top:20px; border:1px solid #ccc; padding-bottom:10px;}
.shuoming dt {height:30px; line-height:30px; font-weight:bold; text-indent:10px;}
.shuoming dd {line-height:20px; padding:5px 20px;}

.wrapper {width:780px;}
/* tmall focus */
#focus {width:780px; height:380px; overflow:hidden; position:relative;}
#focus ul {height:380px; position:absolute;}
#focus ul li {float:left; width:780px; height:380px; 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; width:770px; height:24px; left:0; bottom:8px; padding-left:10px;}
#focus .btn span {display:inline-block; _display:inline; _zoom:1; width:24px; height:24px; line-height:24px; text-align:center; font-size:20px; font-family:"Microsoft YaHei",SimHei; margin-right:10px; cursor:pointer; color:#fff;}
#focus .btn span.on {background:#000; color:#fcc;}
</style>

    <script type="text/javascript" src="./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.5);

    //ΪÊý×Ö°´Å¥Ìí¼ÓÊó±ê»¬Èëʼþ£¬ÒÔÏÔʾÏàÓ¦µÄÄÚÈÝ
    $("#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));

    //Êó±ê»¬ÈëijliÖеÄijdivÀµ÷ÕûÆäͬ±²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>
    <script type="text/javascript" src="./jquery.js"></script>
</head>

<body>
<div class="wrapper">
    <h1>jQuery版仿淘宝商城天猫首页多格焦点图效果</h1>

    <div id="focus">
        <ul>
            <li>
                <div style="left:0; top:0; width:560px; height:380px;"><a href="#"><img src="./a01.jpg" alt="2011ÌÔ±¦É̳Ç×îжà¸ñ½¹µãͼԴ´úÂë" /></a></div>

                <div style="right:0; top:0; width:220px; height:140px;"><a href="#"><img src="./a02.jpg" alt="54173BLOG½¹µãͼÌØЧ¸Ä½ø°æ" /></a></div>
                <div style="right:0; top:140px; width:220px; height:140px;"><a href="http://www.9958.pw/"><img src="./a03.jpg" alt="2011ÌÔ±¦É̳Ç×îжà¸ñ½¹µãͼÍêÃÀ°æ" /></a></div>
                <div style="right:0; bottom:0; width:220px; height:100px;"><a href="#"><img src="./a04.jpg" alt="54173BLOG½¹µãͼÌØЧ" /></a></div>
            </li>

            <li>
                <div style="left:0; top:0; width:780px; height:380px;"><a href="#"><img src="./b01.jpg" alt="2011ÌÔ±¦É̳Ç×îжà¸ñ½¹µãͼ" /></a></div>
            </li>

            <li>
                <div style="left:0; top:0; width:260px; height:210px;"><a href="#"><img src="./c01.jpg" alt="2011ÌÔ±¦É̳Ç×îжà¸ñ½¹µãͼ" /></a></div>

                <div style="left:260px; top:0; width:260px; height:210px;"><a href="http://www.9958.pw/"><img src="./c02.jpg" alt="54173BLOG½¹µãͼÌØЧ" /></a></div>
                <div style="left:0; top:210px; width:520px; height:170px;"><a href="#"><img src="./c03.jpg" alt="2011ÌÔ±¦É̳Ç×îжà¸ñ½¹µãͼ" /></a></div>
                <div style="right:0; top:0; width:260px; height:380px;"><a href="#"><img src="./c04.jpg" alt="54173BLOG½¹µãͼÌØЧ" /></a></div>
            </li>

            <li>
                <div style="left:0; top:0; width:560px; height:380px;"><a href="#"><img src="./d01.jpg" alt="2011ÌÔ±¦É̳Ç×îжà¸ñ½¹µãͼ" /></a></div>
                <div style="right:0; top:0; width:220px; height:140px;"><a href="#"><img src="./d02.jpg" alt="54173BLOG½¹µãͼÌØЧ" /></a></div>
                <div style="right:0; top:140px; width:220px; height:140px;"><a href="#"><img src="./d03.jpg" alt="2011ÌÔ±¦É̳Ç×îжà¸ñ½¹µãͼ" /></a></div>
                <div style="right:0; bottom:0; width:220px; height:100px;"><a href="#"><img src="./d04.jpg" alt="54173BLOG½¹µãͼÌØЧ" /></a></div>

            </li>

            <li>
                <div style="left:0; top:0; width:780px; height:380px;"><a href="#"><img src="./e01.jpg" alt="2011ÌÔ±¦É̳Ç×îжà¸ñ½¹µãͼ" /></a></div>
            </li>
        </ul>
    </div>
</div><!-- wrapper end -->
</body>
</html>
        <style>/* YUI reset */
* {margin:0; padding:0;}
/* body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td { margin:0;padding:0;} */
table {border-collapse:collapse;border-spacing:0;}
fieldset,img { border:0;}
address,caption,cite,code,dfn,em,strong,th,var {font-style:normal;font-weight:normal;}
ol,ul,li {list-style:none;}
caption,th {text-align:left;}
h1,h2,h3,h4,h5,h6 {font-size:100%;font-weight:normal;}
q:before,q:after {content:'';}
abbr,acronym { border:0;}

/* my Download by http://www.9958.pw*/
.clearfix:after {content: "."; display: block; height: 0; clear: both; visibility: hidden;}
.clearfix {zoom:1;}



#focus {width:780px; height:380px; overflow:hidden; position:relative;}

#focus ul {height:380px; position:absolute;}
#focus ul li {float:left; width:780px; height:380px; 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; width:770px; height:24px; left:0; bottom:8px; padding-left:10px;}
#focus .btn span {display:inline-block; _display:inline; _zoom:1; width:24px; height:24px; line-height:24px; text-align:center; font-size:20px; font-family:"Microsoft YaHei",SimHei; margin-right:10px; cursor:pointer; color:#fff;}
#focus .btn span.on {background:#000; color:#fcc;}</style>
                <script></script>