zoukankan      html  css  js  c++  java
  • JavaScript之淡入淡出

    //正常输出
    window.onload=function(){
        var div=document.getElementById('div');
        var timer=null;
        div.style.display='none';
        div.style.opacity='0';
        function fadein(elem, speed, opacity){
            elem.style.display = 'block';
            elem.style.opacity = val / 100;
            var val = 0;
            (function(){
                elem.style.opacity = val / 100;
                val += 10;
                console.log(val);
                if (val <= opacity+500) {
                    setTimeout(arguments.callee, speed);
                }
            })();
        }
        document.getElementById('btn').onclick=function(){
            fadein(div,1000,100);
        }
    }
    //不正常,无法读取elem
    window.onload=function(){
        var div=document.getElementById('div');
        var timer=null;
        div.style.display='none';
        div.style.opacity='0';
        function fadein(elem, speed, opacity){
            elem.style.display = 'block';
            elem.style.opacity = val / 100;
            var val = 0;
            elem.style.opacity = val / 100;
            val += 10;
            console.log(val);
            if (val <= opacity+500) {
                setTimeout(arguments.callee, speed);
            }
        }
        document.getElementById('btn').onclick=function(){
            fadein(div,1000,100);
        }
    }
    //不正常,一直输出10
    window.onload=function(){
        var div=document.getElementById('div');
        var timer=null;
        div.style.display='none';
        div.style.opacity='0';
        function fadein(elem, speed, opacity){
            elem.style.display = 'block';
            elem.style.opacity = val / 100;
            var val = 0;
            elem.style.opacity = val / 100;
            val += 10;
            console.log(val);
            if (val <= opacity+500) {
                setTimeout(function(){
                    fadein(elem, speed, opacity);
                },speed);
            }
        }
        document.getElementById('btn').onclick=function(){
            fadein(div,1000,100);
        }
    }
    //正常输出
    window.onload=function(){
        var div=document.getElementById('div');
        var timer=null;
        div.style.display='none';
        div.style.opacity='0';
        var val = 0;
        function fadein(elem, speed, opacity){
            elem.style.display = 'block';
            elem.style.opacity = val / 100;
            console.log(val);
            if (val <= opacity+500) {
                val += 10;
                elem.style.opacity = val / 100;
                setTimeout(function(){
                    fadein(elem, speed, opacity);
                },speed);
            }
        }
        document.getElementById('btn').onclick=function(){
            fadein(div,1000,100);
        }
    }
  • 相关阅读:
    【HTML】CSS中的margin、border、padding区别
    kill -9 和kill -15,区别,python可以自定义at_exit钩子
    Prometheus 监控Windows机器
    Prometheus下的 promQL
    (4.46)sql server中的rule
    【sql server alwayson】sql servrer alwayson的实例升级
    prometheus+grafana+Alertmanager基本实践
    prometheus+grafana安装部署(入门初探)
    运维监控概述
    mysql基础原理大全
  • 原文地址:https://www.cnblogs.com/chenyongyang/p/7747156.html
Copyright © 2011-2022 走看看