作业20-点击轮播

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>广告图片轮播切换</title>
		<style>
			ul,li{padding: 0;margin: 0; list-style: none;}
.adver{margin: 0 auto; width: 700px; overflow: hidden; height: 454px; position: relative; background: url("images/adver01.jpg");}
ul{position: absolute; bottom:10px; width: 100%; text-align: center;}
ul li{display: inline-block; font-size: 10px; line-height: 20px; font-family: "微软雅黑"; margin: 0 1px; width: 20px; height: 20px; border-radius: 50%; background: #333333; text-align: center; color: #ffffff;}
.arrowLeft,.arrowRight{
    position: absolute;
    width: 30px;
    background:rgba(0,0,0,0.2);
    height: 50px;
    line-height: 50px;
    text-align: center;
    top:200px;
    z-index: 150;
    font-family: "微软雅黑";
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    display: none;
}
.arrowLeft{left: 10px;}
.arrowRight{right: 10px;}
li:nth-of-type(1){
    background: orange;
}
		</style>
	</head>
	<body>
<div class="adver">
    <ul>
        <li onclick="change("adver01.jpg")">1</li>
        <li  onclick="change("adver02.jpg")">2</li>
        <li  onclick="change("adver03.jpg")">3</li>
        <li  onclick="change("adver04.jpg")">4</li>
        <li  onclick="change("adver05.jpg")">5</li>
        <li  onclick="change("adver06.jpg")">6</li>
    </ul>
    <div class="arrowLeft"><</div><div class="arrowRight">></div>
</div>

</body>


<script src="js/jquery-1.12.4.js"></script>
<script type="text/javascript" >
	
	
	

$(document).ready(function(){
    var img=Array("adver01.jpg","adver02.jpg","adver03.jpg","adver04.jpg","adver05.jpg","adver06.jpg");
    var flag=0;
    $(".adver").css("background","url(img/"+img[flag]+")");
    $(".arrowRight").click(function(){
        if(flag==img.length-1){alert("已经是最后一张图片了");}
        else{
            flag++;
            var i=flag+1;
            $(".adver").css("background","url(img/"+img[flag]+")");
            $("li:nth-of-type("+i+")").css("background","orange");
            $("li:nth-of-type("+i+")").siblings().css("background","#333333");
        }
    });

    $(".arrowLeft").click(function(){
        if(flag==0){alert("这是第一张图片了");}
        else{
            flag--;
            var i=flag+1;
            $(".adver").css("background","url(img/"+img[flag]+")");
            $("li:nth-of-type("+i+")").css("background","orange");
            $("li:nth-of-type("+i+")").siblings().css("background","#333333");
        }
    });
    $(".adver").mouseover(function(){
        $(".arrowRight").show();
        $(".arrowLeft").show();
    }).mouseout(function(){
        $(".arrowRight").hide();
        $(".arrowLeft").hide();
    })

});
function change(dd){
    var p=document.getElementById("photo");
    p.setAttribute("src","img/"+dd);
}
</script>
</body>

		
	
</html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值