zoukankan      html  css  js  c++  java
  • dom div重合提示

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    <style>
        #div1{
            height:100px;
            100px;
            position:absolute;
            background:red;
            top:200px;
            left:400px;
            }
        #div2{
            height:100px;
            100px;
            position:absolute;
            background:pink;
            z-index:2;
            text-align:center;
            line-height:100px;
            color:#fff;
            }    
    </style>
    
    <script>
    window.onload = function ()
    {
        var odiv1 = document.getElementById('div1');
        var odiv2 = document.getElementById('div2');
        
        odiv2.onmousedown = function(ev)
        {
            var ev = ev || event;
            var dix = ev.clientX - this.offsetLeft;
            var diy = ev.clientY - this.offsetTop;
            
            document.onmousemove = function (ev)
            {
                var T = ev.clientY - diy;
                var L = ev.clientX - dix;
                if(T < 0)
                {
                    T = 0;
                }else if( T > document.documentElement.clientHeight - odiv2.offsetHeight)
                {
                    T = document.documentElement.clientHeight - odiv2.offsetHeight;
                }
                if(L < 0)
                {
                    L = 0;
                }else if( L > document.documentElement.clientWidth - odiv2.offsetWidth)
                {
                    L = document.documentElement.clientWidth - odiv2.offsetWidth;
                }
                odiv2.style.top = T + 'px';
                odiv2.style.left = L + 'px';
                
                document.title = T + ':' + odiv1.offsetTop + '||' + L + ':' + odiv2.offsetLeft;
                
                if(T == odiv1.offsetTop && L == odiv1.offsetLeft)
                {
                    alert('我们重合了')
                    document.onmousemove = document.onmousedown = null;
                    if(odiv2.releaseCapture)
                    {
                        odiv2.releaseCapture();
                    }
                }
                
                
            };
            document.onmouseup = function ()
            {
                document.onmousemove = document.onmousedown = null;
                if(odiv2.releaseCapture)
                {
                    odiv2.releaseCapture();
                }
            };
            return false;
        }
        
    };
    </script>
    </head>
    
    <body>
    <div id="div1"></div>
    <div id="div2">让我们重合</div>
    </body>
    </html>
  • 相关阅读:
    android120 zhihuibeijing 开机页面
    Android View.onMeasure方法的理解
    android119 侧滑菜单
    android事件拦截处理机制详解
    Android应用在不同版本间兼容性处理
    虚拟机重置密码
    ESXi虚拟机开机进入bios的方法
    [日常工作]Win2008r2 以及更高版本的操作系统安装Oracle10.2.0.5
    Linux下安装oracle的过程
    Oracle18c Exadata 版本安装介质安装失败。
  • 原文地址:https://www.cnblogs.com/mayufo/p/4240918.html
Copyright © 2011-2022 走看看