zoukankan      html  css  js  c++  java
  • 妙味——拖拽改变大小

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>Document</title>
    <style>
    #div1{width: 10px;height: 10px;background: red;position: absolute;bottom: 0;right: 0;}
    #div2{width: 200px;height: 150px;background: #eee;position: relative;}
    </style>
    <script>
    window.onload=function(){
        var oDiv=document.getElementById('div1');
        var oDiv2=document.getElementById('div2');
    
        oDiv.onmousedown=function(ev)
        {
            var oEvent=ev||event;
            var disX=oEvent.clientX-oDiv.offsetLeft;
            var disY=oEvent.clientY-oDiv.offsetTop;
    
            document.onmousemove=function(ev)
            {
                var oEvent=ev||event;
    
                oDiv2.style.width=oEvent.clientX-disX+oDiv.offsetWidth+'px';
                oDiv2.style.height=oEvent.clientY-disY+oDiv.offsetHeight+'px';
            };
    
            document.onmouseup=function()
            {
                document.onmousemove=null;
                document.onmouseup=null;
            };
    
        };
    };
    </script>
    </head>
    <body>
    <div id="div2">
        <div id="div1"></div>
    </div>
    </body>
    </html>
    高否?富否?帅否? 否? 滚去学习!
  • 相关阅读:
    md笔记——HTTP知识
    百万表格难题
    微信接口改良
    md笔记——正则学习
    md笔记——编程术语
    md笔记——微信JS接口
    md笔记——使用 @font-face 引入你喜欢的字体
    博客一年记
    “挨踢”的伙食怎样?
    比尔·盖茨早年
  • 原文地址:https://www.cnblogs.com/baixc/p/3502883.html
Copyright © 2011-2022 走看看