前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >图片缩放中心

图片缩放中心

作者头像
全栈程序员站长
发布2022-07-06 09:26:39
1.6K0
发布2022-07-06 09:26:39
举报
文章被收录于专栏:全栈程序员必看

大家好,又见面了,我是全栈君。

图片缩放中心
图片缩放中心
代码语言:javascript
复制
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>图片放大居中</title>
<meta name="description" content="">
<meta name="keywords" content="">
<style>
	*{margin:0; padding:0;}
    ul,li{margin-right: 0; padding:0;}
    li{list-style:none;}
    a{text-decoration: none;}
    .clearfix:before,.clearfix:after{display: table; content: "";}  
    .clearfix:after{overflow: hidden; clear: both;}
    .clearfix{zoom:1;}
    body{width: 100%; height: 100%; background-color: #000; overflow:hidden;}
    #box{width:330px; margin:100px auto; position: relative;}
    #box li{width:100px; height:100px; background:red; margin:10px 10px 0 0; float:left; color:#fff; line-height:24px;}
</style>
</head>
<body>
<ul id="box" class="clearfix">
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
</ul>
<script src="js/app/move.js"></script>
<script>
    window.onload = function(){
        var aLi = document.getElementById('box').getElementsByTagName('li');
        var arr = [];
        var i=0;
        var zIndex = 1;

        for(i=0; i<aLi.length; i++){
            aLi[i].innerHTML = 'left:'+aLi[i].offsetLeft + 'px' + '<br>top:'+ aLi[i].offsetTop + 'px';
            arr.push({left:aLi[i].offsetLeft,top:aLi[i].offsetTop});
        }

        for(i=0; i<aLi.length; i++){
            aLi[i].index = i;
            aLi[i].style.left = arr[i].left + 'px';
            aLi[i].style.top = arr[i].top + 'px';
            aLi[i].style.position ='absolute';
            aLi[i].style.margin = 0;

            aLi[i].onmouseover = function(){
                this.style.background = 'green';
                this.style.zIndex=zIndex++;
                startMove(this,{
                    width:200,
                    height:200,
                    left:arr[this.index].left - 50,
                    top:arr[this.index].top - 50
                });
            }
            aLi[i].onmouseout = function(){
                this.style.background = 'red';
                startMove(this,{
                    width:100,
                    height:100,
                    left:arr[this.index].left,
                    top:arr[this.index].top
                });
            }
        }

    }
</script>
</body>
</html>

版权声明:本文博客原创文章。博客,未经同意,不得转载。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/117400.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年1月6,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档