zoukankan      html  css  js  c++  java
  • 图片的展开收缩

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
            <link rel="stylesheet" type="text/css" href="../css/public.css"/>
            <style type="text/css">
                #img{width:330px;margin: 100px auto;position: relative;}
                li{float:left;width: 100px;height: 100px;background: red;margin: 10px 0 0 10px;}
            </style>
            <script type="text/javascript" src="../js/rainbow.js"></script>
            <script type="text/javascript">
                window.onload=function(){
                    var aLi=document.getElementsByTagName('li');
                    var zIndex=1;
                    var arr=[];
                    for(var i=0;i<aLi.length;i++){
                        //获取最原始的left top值
                        arr.push({left:aLi[i].offsetLeft,top:aLi[i].offsetTop});
                    }
                    for(var i=0;i<aLi.length;i++){
                        aLi[i].style.left=arr[i].left+'px';
                        aLi[i].style.top=arr[i].top+'px';
                        aLi[i].style.position='absolute';
                        //margin值会和left top 叠加
                        aLi[i].style.margin=0;
                        aLi[i].index=i;
                        aLi[i].onmouseover=function(){
                            this.style.zIndex=zIndex++;
                            this.style.background='green';
                            doMove(this,{200,height:200,left:arr[this.index].left-50,top:arr[this.index].top-50});
                        };
                        aLi[i].onmouseout=function(){
                            this.style.background='red';
                            doMove(this,{100,height:100,left:arr[this.index].left,top:arr[this.index].top});
                        }
                    }
                }
            </script>
        </head>
        <body>
            <ul id="img" >
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
            </ul>
        </body>
    </html>

    效果

  • 相关阅读:
    Object.keys
    数组内容深拷贝的应用
    CSS如何让页脚固定在页面底部
    vue eslint开发 关掉 tab错误提示
    input框,需要隐式显示的时候,不让它自动填充的办法
    关于BFC
    File协议与HTTP协议 以及区别
    关于缓存
    深拷贝浅拷贝 遇到了bug
    聚餐学习
  • 原文地址:https://www.cnblogs.com/rain92/p/6063128.html
Copyright © 2011-2022 走看看