HTML是網(wǎng)頁開發(fā)的基礎(chǔ)語言,JavaScript是一種常用的腳本語言,結(jié)合它們,我們可以創(chuàng)造出多種美觀而實用的特效。下面是一些常用的HTML和JavaScript特效代碼:
//1.鼠標(biāo)懸停特效 <script> function changeColor(element, color){ element.style.backgroundColor = color; } </script> <div onmouseover="changeColor(this, 'red')" onmouseout="changeColor(this, 'white')"> 鼠標(biāo)懸停在這里 </div> //2.輪播圖特效 <script> var index = 0; function changeImg(){ var imgs = document.getElementById("imgs"); var lists = document.getElementById("lists").getElementsByTagName("li"); for(var i=0; i<lists.length; i++){ lists[i].className = ""; } index++; if(index == imgs.children.length){ index = 0; } lists[index].className = "active"; imgs.style.left = -index*800 + "px"; } var timer = setInterval(changeImg, 2000); </script> <div id="imgs"> <img src="img1.jpg"> <img src="img2.jpg"> <img src="img3.jpg"> </div> <ul id="lists"> <li class="active"></li> <li></li> <li></li> </ul>