js相册,照片浮动效果

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        body,p,h1,h2,h3,h4,h5,h6,dl,dd,li{margin:0}
        ol,ul{list-style:none;padding:0;margin:0}
        a{text-decoration:none;}
        img{border:none;}
        .img-panel li{
            position:absolute;
            /*display: inline-block;*/
            width:90px;
            height:120px;
            border: 3px #d9d9d9 solid;
            z-index: 10;
        }
        .img-panel img{
            display: inline;
            width: 100%;
            height:100%;
        }
    </style>
</head>
<body>
<div class="content">
</div>
<script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
    $.ImagePanel = function(options){
        var _options={
            depend:".content",
            img_min_height:120,
            img_max_height:200,
            img_min_width:90,
            img_max_width:150,
            cols:3,
            img_list:["onepiece.jpg","onepiece.jpg","onepiece.jpg","onepiece.jpg","onepiece.jpg","onepiece.jpg","onepiece.jpg","onepiece.jpg","onepiece.jpg","onepiece.jpg","onepiece.jpg","onepiece.jpg"]
        };
        _options = $.extend(_options,options);
        var i, panel,ul,li,img;
        panel = document.createElement("div");
        ul = document.createElement("ul");
        panel.className="img-panel";
        for(i=0;i<_options.img_list.length;i++){
            if(i%_options.cols==0&&i!=0){
                panel.appendChild(ul);
                ul = document.createElement("ul");
            }
            li = document.createElement("li");
            li.style.left =(_options.img_min_width+10) * parseInt(i%_options.cols)+"px";
            li.style.top = (_options.img_min_height+10) * parseInt(i/_options.cols)+"px";

            img = document.createElement("img");
            img.src =_options.img_list[i];
            li.appendChild(img);
            ul.appendChild(li);
        }
        $(_options.depend).append(panel);

        $(".img-panel li").mouseover(function(e){
            $(e.currentTarget).css("z-index","1000");
            $(e.currentTarget).animate({margin:"-"+(_options.img_max_width-_options.img_min_width)/2+"px 0 0 -"+(_options.img_max_height-_options.img_min_height)/2+"px",
                width:_options.img_max_width + "px",height: _options.img_max_height + "px"},500,function(){
                $(e.currentTarget).css("z-index","1000");
            });
        });
        $(".img-panel li").mouseleave(function(e){
            $(e.currentTarget).animate({margin:"0",width:_options.img_min_width+"px",height:_options.img_min_height+"px"},200,function(){
                $(e.currentTarget).css("z-index","10");
            });
        });
    };
    $.ImagePanel({});
</script>
</body>
</html>

 

 

效果

转载于:https://www.cnblogs.com/benson-liu/p/3934916.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值