<!DOCTYPE?html>
<html>
<head>
<meta?charset="utf-8">
<title>opacity</title>
<style?type="text/css">
*{
margin:?0;
padding:?0;
}
#oDiv?{
width:?200px;
height:?200px;
background-color:?blue;
}
</style>
</head>
<body>
<div?id="oDiv"></div>
<script?type="text/javascript">
window.onload?=?function(){
var?oDiv?=?document.getElementById('oDiv');
oDiv.onmouseover?=?function(){
startmove(0.5);
}
oDiv.onmouseout?=?function(){
startmove(1);
}
var?timer?=?null;
function?startmove(target){
clearInterval(timer);
timer?=?setInterval(function(){
var?speed?=?0;
if(oDiv.style.opacity>target){
speed?=?-0.1;
}else{
speed?=?0.1;
};
if?(oDiv.style.opacity==target)?{
clearInterval(timer);
}?else?{
oDiv.style.opacity+=speed;
}
},50);
}
}
</script>
</body>
</html>求解,設(shè)置鼠標(biāo)放置和拿開是透明度漸變和復(fù)原;上面代碼中有哪些錯誤需要更正?還有oDiv.style.opacity==target這句是否能比較?
圖片透明度opacity設(shè)置定時器無效果
一二得三
2017-01-05 23:32:12