javaScript图片滚动轮播,图片下小圆点+两边箭头点击自动关联!

示例代码:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <style>
        *{margin:0;padding:0;}
        #box{position: relative;width:500px;height:300px;margin:100px auto;}
        li{list-style:none;}
        #image{width:500px;height: 300px;position: relative;}
        #image li{position: absolute;top:0;left:0;display: none;}
        #image li.image_show{display: block;}
        #list {position: absolute;bottom: 6px;left: 50%;margin-left: -36px;}
        #list li{ width: 12px;vertical-align: middle;height: 12px;float: left;border-radius: 6px;margin-right: 6px;background-color:#ccc;}
        #list li.list_show{background:red;}
        .round li{width: 40px; height: 40px; background-color: #cccccc;border-radius: 20px;line-height: 40px;color: white;font-size: 28px;font-weight: bold;text-align: center;}
        .round li:hover{background-color: #666;cursor: pointer;}
        .round_l{float: left;margin-left: 5px;}
        .round_r{float:right;margin-right: 5px;}
        .round{width: 500px;position: absolute;top:50%;margin-top: -20px;display: none;}
    </style>
</head>
<body>
    <div id="box">
        <ul id="image">
            <li class="image_show"><img src="1.jpg"  width="500px" height="300px"/></li>
            <li><img src="2.jpg"  width="500px" height="300px"/></li>
            <li><img src="3.jpg"  width="500px" height="300px"/></li>
            <li><img src="4.jpg"   width="500px" height="300px"/></li>
        </ul>
        <ul id="list">
            <li class="list_show"></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
        <ul class="round" id="round">
            <li class="round_l" id="round_l">&lt;</li>
            <li  class="round_r" id="round_r">&gt;</li>
        </ul>
    </div>
<script type="text/javascript">
    /*当鼠标进入盒子,盒子两边的圆形显示效果*/
    function $(id){return document.getElementById(id);}
    $("box").οnmοuseοver=function () {
        $("round").style.display="block";
    }
    $("box").οnmοuseοut=function () {
        $("round").style.display="none";
    }
    var image = $("image").getElementsByTagName("li");
    var list =$("list").getElementsByTagName("li");
    var round_r = $("round_r");
    var round_l = $("round_l");
    for (var i = 0; i < list.length; i++) {
        list[i].index = i;
        /*当鼠标放在图片下方小圆点上时图片自动切换*/
        list[i].onmouseover = function(){
            for(var j = 0;j<list.length;j++){
                list[j].className="";
                image[j].className="";
            }
            this.className="list_show";
            image[this.index].className="image_show";
        }
    }
    round_r.onclick = function(){
        move(false);
    }
    round_l.onclick = function(){
        move(true);
    }
    function move(boolean){
        for(var i = 0;i<list.length;i++){
            if(list[i].className=="list_show"){
                var index = i;
                break;
            }
        }
        boolean ?(index == 0? index= list.length-1:index--):(index == list.length-1? index= 0:index++);
        for(var j = 0;j<list.length;j++){
            list[j].className="";
            image[j].className="";
        }
        list[index].className="list_show";
        image[index].className="image_show";
    }
</script>
</body>
</html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值