这样不行...哪错了?
body,#div1{
margin:0px;
padding:0px;
}
#div1{
width:200px;
height:200px;
background:red;
opacity:0.3;
}
</style>
<script type="text/javascript">
window.onload = function(){
var div = document.getElementById('div1');
div.onmouseover= function(){
var timer = setInterval(function(){
clearInterval(timer);
div.style.opacity += 0.1;
if(div.style.opacity == 1){
clearInterval(timer);
}
},30)
}
div.onmouseout= function(){
var timer = setInterval(function(){
clearInterval(timer);
div.style.opacity-=0.1;
if(div.style.opacity == 0.3){
clearInterval(timer);
}
},30)
}
}