zoukankan      html  css  js  c++  java
  • js操作样式

    <!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">
    <head>
        <title>控制div显示的样式.</title>
        <style type="text/css">
            div
            {
                200px;
                height: 500px;
                background-color: Blue;
                overflow: hidden;
            }
        </style>
        <script type="text/javascript">
            //加载事件
            window.onload = function () {
                //1.btnShow注册点击事件
                document.getElementById('btnShow').onclick = function () {
                    document.getElementById('dv').style.display = '';

                }

                //2.btnHidden注册点击事件
                document.getElementById('btnHidden').onclick = function () {
                    document.getElementById('dv').style.display = 'none';

                }
                //3.btnSlowHidden注册点击事件
                document.getElementById('btnSlowHidden').onclick = function () {
                    var dvobj = document.getElementById('dv');
                    var intervalId = setInterval(function () {
                        //3.1获得层的高度.
                        var h = dvobj.clientHeight;
                        // console.log(h);原来差别在这里,是需要点击html显示的
                        //页面,才能进入..调试代码框.
                        //判断,如果层小于等于零.则设置层样式为none.否则渐隐
                        if (h <= 0) {
                            dvobj.style.display = 'none';
                            clearInterval(intervalId);

                        } else {
                            dvobj.style.height = h - 5 + 'px';

                        }
                    }, 100);

                }


                //4.btnSlowShow注册点击事件
                document.getElementById('btnSlowShow').onclick = function () {
                    var dvobj = document.getElementById('dv');
                    var intervalId = setInterval(function () {
                        //3.1获得层的高度.
                        var h = dvobj.clientHeight;

                        //判断,如果层小于等于500.则让高度累加.直到达到设定高度,显示层.并终止setInterval事件.
                        if (h <= 500) {
                            dvobj.style.height = h + 5 + 'px';
                        } else {

                            dvobj.style.display = '';
                            clearInterval(intervalId);

                        }
                    }, 100);

                }

            }
        </script>
    </head>
    <body>
        <input type="button" name="name" value="渐隐" id="btnSlowHidden" />
        <input type="button" name="name" value="渐显" id="btnSlowShow" />
        <input type="button" name="name" value="显示" id="btnShow" />
        <input type="button" name="name" value="隐藏 " id="btnHidden" />
        <div id="dv">
        委托和事件
        <br />
        泛型<br />
        通信<br />
        显示<br />

        </div>
         
        xxxxxxxxxxxx
    </body>
    </html>

  • 相关阅读:
    java中JSON转换
    使用Admin监控
    linux安装tomcat
    SpringBoot整合Redis
    linux6.8安装docker
    使用Actuator监控
    SpringBoot集成阿里巴巴Druid监控
    使用Log4j日志处理
    SpringBoot多数据源
    SpringBoot文件上传下载
  • 原文地址:https://www.cnblogs.com/nqsan/p/3192320.html
Copyright © 2011-2022 走看看