js 애니메이션의 간단한 운동 2

1947 단어
투명도 변화
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title> </title>
	<style>
		.animation{
			background-color: green;
			height: 100px;
			width: 100px;
            filter:alpha(opacity:30);
            opacity: 0.3;
		}
	</style>
</head>
<body>
	<div id="test" class="animation">animation</div>
</body>
 <script type="text/javascript">
    window.onload = function(){
    	var test = document.getElementById("test"),
            timer = null,
            alpha = 30;
        test.onmouseover = function(){
            startAnimation(100);
        }

        test.onmouseout = function(){
            startAnimation(30);
        }

        function startAnimation (alphaTarget) {
            clearInterval(timer);
            timer = setInterval(function(){
                if (alphaTarget == alpha) {
                    clearInterval(timer);
                    return;
                };
                if(alphaTarget > alpha){
                    alpha += 1;
                    test.style.filter = 'alpha(opacity:'+alpha+')';
                    test.style.opacity = alpha/100;
                }else{
                    alpha -= 1;
                    test.style.filter = 'alpha(opacity:'+alpha+')';
                    test.style.opacity = alpha/100;
                }
            },100)
        }
    	
    }
 </script>
</html>

테스트를 보실 수 있습니다.style.filter='alpha(opacity:100)'이거 IE 방식이에요.
     test.style.opacity는 DOM 브라우저의 방식입니다.

좋은 웹페이지 즐겨찾기