• 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);
        }
    }
  • 相关阅读:
    Linux常用指令
    【OOM】记录一次生产上的OutOfMemory解决过程
    (转载)springboot + rabbitmq发送邮件(保证消息100%投递成功并被消费)
    【Idea】实用插件列表
    【工厂模式】-企业微信应用配置代码优化
    【日志追踪】(微服务应用和单体应用)-logback中的MDC机制
    行内元素进行绝对(absolute),固定(fixed)定位后会变成块级元素·
    JQuery
    单行文字居中
    后代元素 span:first-child{...}
  • 原文地址:https://www.cnblogs.com/chenyongyang/p/7747156.html
Copyright © 2020-2023  润新知