<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> div{ width:50px; height:50px; border:1px solid #000000; } </style> </head> <body> <div class="one"> 1 <div class="two" style="margin-left: 50px;"> 2 <div class="three" style="margin-left: 50px;"> 3 <div class="four" style="margin-left: 50px;">4</div> </div> </div> <div class="one">1</div> </div> </body> <script> var one=document.getElementsByClassName("one")[0]; var i; function visit(node){ i +=400; node.style.backgroundColor="#fff"; setTimeout(function(){ node.style.backgroundColor="#0f0"; },i) } function qx(root){ if (root) { //如果根元素村子 visit(root); //执行动画 var children = root.getElementsByName('div'); for (var i = 0; i < children.length; i++) { //循环 //只选择子一层div if(children[i].parentNode == root) { //将子元素等于根元素 qx(children[i]); //那么就进行添加 } } } } qx(one) </script> </html>
fdsgasgg
相关分类