<!DOCTYPE?html>
<html?lang="en">
<head>
????<meta?charset="UTF-8">
????<title>透明度動(dòng)畫</title>
????<style?type="text/css">
????????.div{
????????????width:?300px;
????????????height:?300px;
????????????background-color:?blue;
????????????opacity:?0.5;
????????}
????</style>
????<script?type="text/javascript">
????????window.onload=function(){
????????????var?div?=?document.getElementById("div")
????????????div.onmouseover=function(){
????????????????startMove(1);
????????????}
????????????div.onmouseout=function(){
????????????????startMove(0.5);
????????????}
????????}
????????var?timer;
????????var?opacity=0.5;
????????function?startMove(itarget){
????????????clearInterval(timer)
????????????var?div?=?document.getElementById("div")
????????????timer?=?setInterval(function(){
????????????????var?speed?=?0;
????????????????if?(?div.style.opacity>itarget){
????????????????????speed=-0.5;
????????????????}else?{
????????????????????speed=0.5;
????????????????}
????????????????if(opacity==itarget){
????????????????????clearInterval(timer)
????????????????}else?{
????????????????????opacity?+=speed;
????????????????????div.style.opacity=opacity;
????????????????}
????????????},30)
????????}
????</script>
</head>
<body>
?<div?class="div"></div>
</body>
</html>
請(qǐng)問這哪里錯(cuò)了
夢(mèng)要夠瘋才能變成英雄雄雄
2015-12-06 21:31:26