Based on ReplaceChild to make simple phagocytosis effects _javascript skills

Source: Internet
Author: User

Effect Demo Chart:

Source view

"HTML code description"

<ul class= "list" id= "list" >
  <li class= "in" >1</li>
  <li class= "in" >2</li>
  <li class= ' in ' >3</li>
  <li class= ' in ' >4</li>
  <li class= ' in ' >5</li>
  <li class= "in" >6</li>    
</ul>

"CSS Code description"

. in{
  height:20px;
  line-height:20px;
  width:20px;
  Background-color:blue;
  Text-align:center;
  Color:white;
}

"JS Code description"

<script>
var olist = document.getElementById (' list ');
Add an LI element
var oadd = document.createelement (' li ');
Sets the CSS style for the new element
oadd.classname = "in";
OAdd.style.cssText = ' background-color:red;border-radius:50% ';
1s oadd replaces No. 0 li
settimeout (function () {
  olist.replacechild (oadd,document.getelementsbytagname (' li ') [0] );
  1s after the execution of Incrementnumber function
  settimeout (incrementnumber,1000);  
},1000);
function Incrementnumber () {
  //Get olist 1th li
  var oLi1 = document.getelementsbytagname (' li ') [1];
  If present, replace the process
  if (oLi1) {
     olist.replacechild (oadd,oli1);
     SetTimeout (incrementnumber,1000);    
  }
</script>

The above content for everyone to share based on the replacechild production of simple phagocytosis effects, I hope you like.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.