var menuList = document.getElementsByClassName('menu-item'); for(var i = 0; i < menuList.length; i++){ menuList[i].addEventListener('mouseleave', function(){ this.classList.remove('hover'); }) }
function displayTime(){ var date = new Date(); var hours = date.getHours(); var minutes = date.getMinutes(); var seconds = date.getSeconds(); var timeString = hours + ':' + minutes + ':' + seconds; document.getElementById('time').innerHTML = timeString; } setInterval(displayTime, 1000);
var images = [ 'image1.jpg', 'image2.jpg', 'image3.jpg', 'image4.jpg' ]; var currentImageIndex = 0; function changeImage(){ var imageElement = document.getElementById('my-image'); imageElement.src = images[currentImageIndex]; currentImageIndex++; if(currentImageIndex >= images.length){ currentImageIndex = 0; } } setInterval(changeImage, 5000);
上一篇javascript 錨
下一篇div 滾動軸