zoukankan      html  css  js  c++  java
  • (38)JS运动之淡入淡出

    基本思路:使用样式filter。可是要区分IE浏览器和chrom、firefox的不同,详细也是用定时器来实现。

    <!DOCTYPE HTML>
    <!--
    	
    -->
    <html>
    <head>
    <meta charset="utf-8">
    <title></title>
    <style>
    #div1{
    	200px;
    	height:200px;
    	background:red;
    	filter:alpha(opacity:30);opacity:0.3;
    }
    
    
    </style>
     
    
    <script>
    window.onload=function ()
    {
    	var oDiv=document.getElementById('div1');
    	oDiv.onmouseover=function ()
    	{
    		startMove(100);
    	};
    	oDiv.onmouseout=function ()
    	{
    		startMove(30);
    	};
    
    };
    var alpha=30;//透明度变量,由于样式那里初始是30
    var timer=null;
    function startMove(iTarget){
    	var oDiv=document.getElementById('div1');	
    	
    	clearInterval(timer);
    	timer=setInterval(function (){
    		
    	var speed=0;
    	if(alpha<iTarget)
    	{
    		speed=1;
    	}
    	else{
    		speed=-1;
    	}
    	if(alpha==iTarget)
    	{	
    		clearInterval(timer);
    	}
    	else
    	{
    		alpha+=speed;
    		oDiv.style.filter='alpha(opacity:'+alpha+')';//IE的透明度
    		oDiv.style.opacity=alpha/100;//谷歌、火狐浏览器。满的值是1,不是100。因此除以100
    	}
    	
    	},30)
    
    }
    </script>
    </head>
    <body>
       
       <div id="div1"></div>
    
    </body>
    </html>

    效果图:

  • 相关阅读:
    NPTL 线程同步方式
    mysql事物处理
    DHCP服务器-DNS服务器-Samba服务器
    NTP服务器
    wsgiref 源代码分析
    集群负载均衡LVS
    百万数据查询优化技巧三十则
    Shell 基本运算符
    Shell 数组
    Shell 传递参数
  • 原文地址:https://www.cnblogs.com/tlnshuju/p/6724336.html
Copyright © 2011-2022 走看看