<!DOCTYPE?html>
<html>
<head>
<meta?charset="utf-8">
<meta?http-equiv="X-UA-Compatible"?content="IE=edge,chrome=1">
<title>Examples</title>
<meta?name="description"?content="">
<meta?name="keywords"?content="">
<link?href=""?rel="stylesheet">
<style?type="text/css">
*{margin:?0;padding:?0;}
#box{width:?200px;
height:?200px;
background-color:?blue;
opacity:?0.3;
margin-left:?50px;}
</style>
</head>
<body>
????<div?id?=?"box"></div>
<script?type="text/javascript">
window.onload?=?function(){
var?box1?=?document.getElementById('box');
box1.onmouseover?=?function(){changeTo(1.0)};
box1.onmouseout?=?function(){changeTo(0.3)};
}
var?timer?=?null,alpha?=?0.3;
function?changeTo(a){
clearInterval(timer);
var?box1?=?document.getElementById('box');
timer?=?setInterval(function(){
if?(alpha?<?a?){
alpha?+=?0.1;
box1.style.opacity?=?alpha;?}
else?if(alpha?>?a){
alpha?-=?0.1;
box1.style.opacity?=?alpha;?
}
else??{clearInterval(timer);}
},300)
}
</script>
</body>
</html>
2016-12-07
按照老師的做法 ?把透明度改成100、 30 然后最后設(shè)定時去除以100即可??赡苁且驗榈讓覬S運算小數(shù)的時候因為進(jìn)制關(guān)系無法準(zhǔn)確算到0.3或者1.0……
2016-12-06
透明度到底是為了變?yōu)?.1還是0.3?
2016-12-06
把定時器的時間值設(shè)置小點