• 利用javascript(自定义事件)记录尺寸可变元素的尺寸变化过程


    1.效果图

    2.源码

    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <style type="text/css">
            div{
                border:1px solid black;
                width:200px;
                height: 95px;
                resize:both;
                overflow: auto;
            }
        </style>
        <script type="text/javascript">
            function showSize(elementSize) {
                console.log(""+elementSize.width+";height:"+elementSize.height);
            }
            HTMLDivElement.prototype.onsizechange = function (handleFunction) {
                var element = this;
                var lastWidth = element.clientWidth;
                var lastHeight = element.clientHeight;
    
                setInterval(function () {
                    if (lastWidth === element.clientWidth && lastHeight === element.clientHeight)
                        return;
                    if (typeof (handleFunction) == 'function') {
                        lastWidth = element.clientWidth;
                        lastHeight = element.clientHeight;
                        handleFunction({  lastWidth, height: lastHeight });
    
                    }
                }, 100);
                return element;
            };
            window.onload = function () {
                var myDiv = document.getElementById("myDiv");
                myDiv.onsizechange(showSize);
            };
        </script>
    </head>
    <body>
    <div id="myDiv"><p>尺寸可变元素<br/>200px;height:95px</p></div>
    </body>
    </html>
  • 相关阅读:
    每日日报30
    每日作业报告
    每日作业报告
    每日作业报告
    每日作业报告
    每日作业报告
    每日作业报告
    每日作业报告
    每日作业报告
    Java学习的第四十三天
  • 原文地址:https://www.cnblogs.com/zhuwenqi2016/p/8664778.html
Copyright © 2020-2023  润新知