看了又看還是沒發(fā)現(xiàn)哪里錯(cuò)了,透明度沒反應(yīng)
<!doctype html>
<html>
<head>
?<meta charset="UTF-8">
?<title>透明度</title>
?<style type="text/css">
?*{margin:0;padding: 0;}
????? #div1{
??????? float:left;
??????? margin:10px;
????? ?background: red;
????? ?height:200px;
????? ?width:200px;
????? ?left:0px;
????? ?top:80px;
??????? opacity:0.3;
??????? filter:alpha(opacity:30);//IE
????? }
????
?</style>
<script type="text/javascript">
???? window.onload=function(){
?????? var oDiv=document.getElementsByTagName('div1');
?????? for(var i=0;i<oDiv.length;i++){
?????? oDiv[i].alpha=30;
?????? oDiv[i].onmouseover=function(){
???????? startmove(this,100);
?????? }
?????? oDiv[i].onmouseout=function(){
???????? startmove(this,30);
?????? }
????? }
???? }
???? //var timer=null;
???? //var alpha=30; 多個(gè)物體是不能使用公共樣式,需要對(duì)每一個(gè)對(duì)象都定義
???? var speed=0;
???? function startmove(obj,goal){
?????
?????? //var oDiv=document.getElementsByTagName('div1');
?????? clearInterval(obj.timer);
?????? obj.timer=setInterval(function(){
????
?????? ?if(obj.alpha==goal){???? //判斷加在定時(shí)器里面
?????? ?clearInterval(obj.timer);
?????? }
?????? else{
????????? if(goal>obj.alpha){
??????????? speed=3;
????????? }
????????? else{speed=-3;}
????????? obj.alpha+=speed;
????????? obj.style.opacity=obj.alpha/100;
????????? obj.style.filter='alpha(opacity:'+obj.alpha+')';//IE
?????? }?
??? },30)
? }
???
</script>
</head>
<body>
?<div id="div1"></div>
?<div id="div1"></div>
? <div id="div1"></div>
</body>
</html>
2017-04-11
獲取的時(shí)候錯(cuò)了 應(yīng)該是document.getElementsByTagName('div');
2017-04-07
你倒數(shù)第3個(gè)花括號(hào)寫多了一個(gè)
2017-04-07
我覺得你錯(cuò)在startmove()這個(gè)函數(shù)內(nèi)容里 你自己整理下