问答详情
源自:4-1 JS多物体动画

求大神 怎么运行不变色

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8" />

<title>透明</title>

<style type="text/css">

    *{

    margin: 0px;

    padding: 0px;

    }

.div1{

width: 200px;

height: 200px;

background: red;

filter: alpha(opacity:30);

opacity: 0.3;

margin: 10px;

float: left;

}

</style>

<script type="text/javascript">

window.onload=function(){

var oDiv=document.getElementsByClassName('div');

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,

//    speed=0,

//    alpha=30;

function startmove(obj,iTarget){

var speed=0;

clearInterval(obj.timer);

 obj.timer=setInterval(function(){

if(obj.alpha>iTarget){

speed=-10;

}else{

speed=10;

}

  

   if(obj.alpha==iTarget){

    clearInterval(obj.timer);

   }

   else{

     

    obj.alpha+=speed;

       obj.style.filter='alpha(opactiy:"+obj.alpha+")';

       obj.style.opacity=obj.alpha/100;}

    },30)

   }

</script>

</head>

<body>

<div class="div1"></div>

<div class="div1"></div>

<div class="div1"></div>

<div class="div1"></div>

<div class="div1"></div>

</body>

</html>


提问者:hey_whatsup 2016-07-31 19:54

个回答

  • 向死而生3491500
    2016-09-19 13:36:31

    这是你的抓取class  JS代码“var oDiv=document.getElementsByClassName('div');”

    这是你body里的代码  

    <div class="div1"></div>

    <div class="div1"></div>

    <div class="div1"></div>

    <div class="div1"></div>

    <div class="div1"></div>


      应该如下 ‘’var oDiv=document.getElementsByClassName('div1');‘’

      或者如下  ” var oDiv=document.getElementsByTagName('div');”


  • Dling
    2016-08-17 15:45:09

    var oDiv = document.getElementsByClassName('div');
    var oDiv = document.getElementsByClassName('div1');
    <div class="div1"></div>
    <div class="div1"></div>
    <div class="div1"></div>
    <div class="div1"></div>
    <div class="div1"></div>


  • yyou
    2016-07-31 20:27:41

    filter: alpha(opacity=30);