Gambar tunjuk cara kesan:
[Perihalan kod HTML]
<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>
[penerangan kod CSS]
.in{ height: 20px; line-height: 20px; width: 20px; background-color: blue; text-align: center; color: white; }
[penerangan kod JS]
<script> var oList = document.getElementById('list'); //新增一个li元素 var oAdd = document.createElement('li'); //设置新增元素的css样式 oAdd.className = "in"; oAdd.style.cssText = 'background-color:red;border-radius:50%'; //1s后oAdd替换第0个li setTimeout(function(){ oList.replaceChild(oAdd,document.getElementsByTagName('li')[0]); //1s后执行incrementNumber函数 setTimeout(incrementNumber,1000); },1000); function incrementNumber(){ //获取oList中第1个li var oLi1 = document.getElementsByTagName('li')[1]; //若存在则进行替换处理 if(oLi1){ oList.replaceChild(oAdd,oLi1); setTimeout(incrementNumber,1000); } } </script>
Kandungan di atas berkongsi dengan anda kesan khas telan mudah berdasarkan replaceChild. Saya harap anda menyukainya.