search
HomeCommon ProblemJavaScript special effects code collection

JavaScript special effects code collection

Dec 14, 2023 am 09:44 AM
javascriptspecial effects code

JavaScript is a very powerful programming language that can be used to create a variety of dynamic and interactive web page effects. The following are some common JavaScript special effect code examples:

1. Mouseover effect

html
nbsp;html>  
  
  
 <title>Hover Effect</title>  
 <style>  
 .hover-effect {  
 width: 100px;  
 height: 100px;  
 background-color: #f00;  
 transition: background-color 0.5s ease;  
 }  
 .hover-effect:hover {  
 background-color: #0f0;  
 }  
 </style>  
  
  
 <div></div>  
  

2. Carousel effect

html
nbsp;html>  
  
  
 <title>Carousel Effect</title>  
 <style>  
 .carousel {  
 width: 300px;  
 height: 200px;  
 overflow: hidden;  
 position: relative;  
 }  
 .carousel img {  
 width: 100%;  
 height: auto;  
 }  
 .carousel img:first-child {  
 position: absolute;  
 left: 0;  
 top: 0;  
 }  
 .carousel img:nth-child(2) {  
 position: absolute;  
 right: 0;  
 top: 0;  
 }  
 .carousel img:nth-child(3) {  
 position: absolute;  
 left: 0;  
 bottom: 0;  
 }  
 .carousel img:nth-child(4) {  
 position: absolute;  
 right: 0;  
 bottom: 0;  
 }  
 </style>  
  
  
 <div>  
 <img  src="/static/imghwm/default1.png" data-src="image1.jpg" class="lazy" alt="JavaScript special effects code collection" >  
 <img  src="/static/imghwm/default1.png" data-src="image2.jpg" class="lazy" alt="JavaScript special effects code collection" >  
 <img  src="/static/imghwm/default1.png" data-src="image3.jpg" class="lazy" alt="JavaScript special effects code collection" >  
 <img  src="/static/imghwm/default1.png" data-src="image4.jpg" class="lazy" alt="JavaScript special effects code collection" >  
 </div>  
 <script>  
 var carousel = document.querySelector(&#39;.carousel&#39;);  
 var images = carousel.querySelectorAll(&#39;img&#39;);  
 var currentIndex = 0;  
 setInterval(function() {  
 images[currentIndex].style.display = &#39;none&#39;;  
 currentIndex = (currentIndex + 1) % images.length;  
 images[currentIndex].style.display = &#39;block&#39;;  
 }, 2000); // 每2秒切换一次图片  
 </script>  
  

The above is the detailed content of JavaScript special effects code collection. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)