Jquery自动切换图片

<!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>无标题文档</title>
<script src="http://www.codefans.net/ajaxjs/jquery-1.6.2.min.js" type="text/javascript"></script>
<link href="XjhHomePage.css" rel="stylesheet" type="text/css"/>
<script>
//jquery 图片自动切换
    $(function ()
{
var ul = $(".lxfscroll");
        var li = $(".lxfscroll li");
        var tli = $(".lxfscroll-title li");
var speed = 350;
        var autospeed = 3000;
var i = 1;
var index = 0;
var n = 0;
/*标题按钮事件 */
            function lxfscroll() {
                var index = tli.index($(this));
                tli.removeClass("hover");
                $(this).addClass("hover");


                ul.css({ "left": "0px" });
                li.css({ "left": "0px" });
                li.eq(index).css({ "z-index": i });
                li.eq(index).css({ "left": "540px" });
                ul.animate({ left: "-540px" }, speed);
                i++;


            };
            /* 自动轮换 */
            function autoroll() {
                if (n >= 5) {
                    n = 0;
                }
                tli.removeClass("hover");
                tli.eq(n).addClass("hover");
                ul.css({ "left": "0px" });
                li.css({ "left": "0px" });
                li.eq(n).css({ "z-index": i });
                li.eq(n).css({ "left": "540px" });


                n++;
                i++;
                timer = setTimeout(autoroll, autospeed);
                ul.animate({ left: "-540px" }, speed);
            };
            /* 鼠标悬停即停止自动轮换 */
            function stoproll() {
                li.hover(function () {
                    clearTimeout(timer);
                    n = $(this).prevAll().length + 1;
                }, function () {
                    timer = setTimeout(autoroll, autospeed);
                });
                tli.hover(function () {
                    clearTimeout(timer);
                    n = $(this).prevAll().length + 1;
                }, function () {
                    timer = setTimeout(autoroll, autospeed);
                });
            };
            tli.mouseenter(lxfscroll);
            autoroll();
            stoproll();
    });
</script>
</head>


<body>


                <div class="focus">
                    <ul class="lxfscroll">
                        <li><a href="#"
                            target="_blank">
                            <img src="Imge/8c78ce0c-4af6-4205-abc7-56f62ff4af6c.jpg" width="536" height="278">
                            
                            </a> </li> 
                        <li><a href="#"
                            target="_blank">
                            <img src="Imge/6019718e-6ab6-42ec-86e2-0fecc91626c7.jpg" width="536" height="278"></a> </li>
                        <li><a href="#"
                            target="_blank">
                            <img src="Imge/a7e5177d-acc2-4aa1-9f71-a6094e9eb8b8.jpg" width="536" height="278">
                        </a></li>
                        <li><a href="#"
                            target="_blank">
                            <img src="Imge/c9c3c50a-f1a9-4797-96d9-2f92c804f1f3.jpg" width="536" height="278"></a>
                        </li>
                        <li><a href="#"
                            target="_blank">
                            <img src="Imge/1.jpg" width="536" height="278"></a>
                        </li>
                    </ul>
                    <ul class="lxfscroll-title">
                      <li class="hover">1</li>
                        <li class="">2</li>
                        <li class="">3</li>
                        <li class="">4</li>
<li class="">5</li>
                  </ul>
</div>




</body>

</html>



/*XhjHomePage.css*/

.focus
{
    width: 536px;
    margin-left: 0;
    margin-right: auto;
    margin-top: 10px;
    position: relative;
    height: 300px; /*border: 4px solid #EFEFEF;*/
    overflow: hidden;
}
ul
{
margin:0px;
padding:0px;
}
.focus .lxfscroll
{
    /*width: 536px;
    margin-left: 0;
    margin-right: auto;*/
    margin-top: 0px;
    
    position: relative;
     /*border: 4px solid #EFEFEF;*/
    list-style: none;
}


.focus .lxfscroll li
{
    height: 300px;
    width: 536px;
    text-align: center;
    height: 278px;
    position: absolute;
    font-size: 40px;
    font-weight: bold;
}


.lxfscroll-title
{
    position:absolute;
    display:block;
    height: 7px;
    width: 536px;
    text-align: center;
    margin-top: 284px;
}




.focus .lxfscroll-title li
{
    width: 30px;
    height: 8px;
    margin: 0 10px;
    background-color: #e6e6e6;
    display: inline-block;
    _display: inline;
    overflow: hidden;
    vertical-align: top;
    zoom: 1;
    line-height: 40px;
    cursor: pointer;
}


.focus .lxfscroll-title .hover
{
    background-color: #b01b15;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值