What we Think , latest news

使用计时器做一个渐变效果的function

    <div id="a" style="width: 100px;height: 100px;background-color: black">
    <div id="b" onclick="fadeout(a,b)" style="width: 100px;height: 100px;color:yellow; ">点击此方块</div>
    </div>
    <script>
        function fadeout(element){
            var fin=1.00;
            var fin3=document.getElementById('c');
            var ddd=document.getElementById('ddd');
            setInterval(function(){//核心部分
                if(fin>0){ //大于0的时候做出改变
                    var fin2=element.style.opacity=fin-0.01;//相当于1/100
                    fin=fin2;//需要给全局变量进行赋值才可以改变结果
                }
                if(fin<1){
                    console.log("正在改变颜色中。。。")
                }

            },10)//10x100相当于1000毫秒为1秒-此动画时间为1秒
        };
    </script>

 

posted @ 2016-03-28 14:48  sakura丶shadow  阅读(319)  评论(0编辑  收藏  举报