哪位大神幫我看看,為什么我就是沒有效果,按照老師的看了好幾遍了
<!DOCTYPE html>
<html>
<head lang="en">
? ?<meta charset="UTF-8">
? ?<title></title>
? ?<style>
? ? ? ?#div1{
? ? ? ? ? ?width:200px;
? ? ? ? ? ?height:200px;
? ? ? ? ? ?background:red;
? ? ? ? ? ?filter:alpha(opacity:30); ? /*支持Firefox, Safari, Chrome*/
opacity:0.3; ? ? ? ? ? /*支持IE*/
}
? ?</style>
? ?<script>
? ? ? ?window.onload=function(){
? ? ? ? ? ?var oDiv=document.getElementById("div1");
? ? ? ? ? ?oDiv.onmouseover=function(){
? ? ? ? ? ? ? ?startMove(100);
? ? ? ? ? ?}
? ? ? ? ? ?oDiv.onmouseout=function(){
? ? ? ? ? ? ? ?startMove(30);
? ? ? ? ? ?}
? ? ? ?}
? ? ? ?var timer=null;
? ? ? ?var alpha=30;
? ? ? ?var oDiv=document.getElementById("div1");
? ? ? ?function startMove(target){
? ? ? ? ? ?clearInterval(timer);
? ? ? ? ? ?timer=setInterval(function(){
? ? ? ? ? ? ? ?var speed=0;
? ? ? ? ? ? ? ?if(alpha>target){
? ? ? ? ? ? ? ? ? ?speed=-10;
? ? ? ? ? ? ? ?}else{
? ? ? ? ? ? ? ? ? ?speed=10;
? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?if(alpha==target){
? ? ? ? ? ? ? ? ? ?clearInterval(timer);
? ? ? ? ? ? ? ?}else{
? ? ? ? ? ? ? ? ? ?alpha+=speed;
? ? ? ? ? ? ? ? ? ?oDiv.style.filter='alpha(opacity:'+alpha+')';
? ? ? ? ? ? ? ? ? ?oDiv.opacity=alpha/100;
? ? ? ? ? ? ? ?}
? ? ? ? ? ?},30)
? ? ? ?}
? ?</script>
</head>
<body>
? ?<div id="div1"></div>
</body>
</html>
2016-01-22
(1)var oDiv=document.getElementById("div1");把這句放在startMove函數(shù)里面;
(2)?oDiv.opacity=alpha/100;這一句寫少了style