zoukankan      html  css  js  c++  java
  • 淡入淡出实现

    <!DOCTYPE HTML>
    <html lang="en-US">
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
            #box {200px; height:200px; background:red;}
        </style>
    </head>
    <body>
        
        <div id="box">
        
        </div>
        <br />
        <button>淡出</button>
        <button>淡入</button>
        
        <script type="text/javascript"> 
            var box = document.getElementById('box');
            var btns = document.getElementsByTagName('button'); 
            var t = null; //定时器
            //淡出
            btns[0].onclick = function(){
                clearInterval(t);
                var opa = 1; //默认初识值
                t = setInterval(function(){
                    opa -= 0.05;
                    box.style.opacity = opa;
                    console.log(opa);
                    if (opa <= 0) {
                        opa = 0; //校正一下
                        clearInterval(t);
                    }
                },100);
            }
            //淡入
            btns[1].onclick = function(){
                clearInterval(t);
                var opa = 0; //默认初始值
                t = setInterval(function(){
                    opa += 0.05;
                    box.style.opacity = opa;
                    if (opa >= 1) {
                        opa = 1;
                        clearInterval(t);
                    }

                },100);
            }
        
        </script>
    </body>
    </html>
  • 相关阅读:
    坚持的力量 第十五篇
    <QT障碍之路>qt中使用串口类接收数据不完整
    《开发板 — ping得通本地,但是不能上网。route设置默认网关》
    《海思3531D 搭建环境出现的一些问题》
    《应用编程 — 进程通信 — 命名管道FIFO》
    <QT学习>QT中串口QSerialport类学习与使用
    网络视频工具/网站
    [恢]hdu 1701
    [恢]hdu 1425
    [恢]hdu 2523
  • 原文地址:https://www.cnblogs.com/xiaobaizitaibai/p/8711217.html
Copyright © 2011-2022 走看看