使用jQuery仿苹果官网焦点图特效

2020-05-24 21:30:23易采站长站整理

    -webkit-box-shadow:0 0 3px #AAAAAA;
    box-shadow:0 0 3px #AAAAAA;
    /* CSS3 Rounded Corners */
    -moz-border-radius-bottomleft:4px;
    -webkit-border-bottom-left-radius:4px;
    border-bottom-left-radius:4px;
    -moz-border-radius-bottomright:4px;
    -webkit-border-bottom-right-radius:4px;
    border-bottom-right-radius:4px;
    border:1px solid white;
    background:url(img/panel.jpg) repeat-x bottom center #ffffff;
    /* The width of the gallery */
    width:920px;
    overflow:hidden;
}
#slides{
    /* This is the slide area */
    height:400px;
    /* jQuery changes the width later on to the sum of the widths of all the slides. */
    width:920px;
    overflow:hidden;
}
.slide{
    float:left;
}
#menu{
    /* This is the container for the thumbnails */
    height:45px;
}
ul{
    margin:0px;
    padding:0px;
}
li{
    /* Every thumbnail is a li element */
    width:60px;
    display:inline-block;
    list-style:none;
    height:45px;
    overflow:hidden;
}
li.inact:hover{
    /* The inactive state, highlighted on mouse over */
    background:url(img/pic_bg.png) repeat;
}
li.act,li.act:hover{
    /* The active state of the thumb */
    background:url(img/active_bg.png) no-repeat;
}
li.act a{
    cursor:default;
}
.fbar{
    /* The left-most vertical bar, next to the first thumbnail */
    width:2px;
    background:url(img/divider.png) no-repeat right;
}
li a{
    display:block;
    background:url(img/divider.png) no-repeat right;
    height:35px;
    padding-top:10px;
}
a img{
    border:none;
}
CSS代码也非常简单,都是一些简单设置而已。

jQuery代码:


$(document).ready(function(){
    /* This code is executed after the DOM has been completely loaded */
    var totWidth=0;
    var positions = new Array();
    $(‘#slides .slide’).each(function(i){
        /* Traverse through all the slides and store their accumulative widths in totWidth */
        positions[i]= totWidth;