jQuery生成图片列表

<!DOCTYPE html>
<html>
    <head>
        <title>生成图片列表</title>
        <style type="text/css">
            *{ margin: 0px; padding: 0px; }
            .bpp4{ width: 700px; height: 280px; padding-left: 10px; padding-bottom: 10px; border: 1px solid #333333; margin: 30px auto; }
            .bpp4 div{ width: 128px; height: 128px; margin-top: 10px; margin-right: 10px; float: left; transition: all .1s; }
            .bpp4 div.current{ box-shadow: 2px 2px  5px  #808080, -2px -2px 5px #808080; transform: translateZ(2000px); }
        </style>
        
        <script src="../../jquery-3.4.1.min.js"></script>

    </head>
    <body>
        <div class="bpp4">

        </div>

        <script type="text/javascript">
            $(document).ready(function(){
                // 创建数组
                var colorimg = ["pink", "yellow", "orange", "green", "blue", "grey", "red", "purple", "bisque", "olive"];
                // 生成子元素
                for(var i in colorimg){
                    $(".bpp4").append("<div></div>");
                }
                // 遍历元素
                $(".bpp4 div").each(function(i){
                    $(this).css("background", colorimg[i]);
                    $(this).hover(function(){
                        this.className += "current";
                    }
                    ,function(){
                        this.className = "";
                    });
                });
            });
        </script>
    </body>
</html>

               效果图:

                            

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值