ホームページ  >  記事  >  JavaScript 特殊効果コード集

JavaScript 特殊効果コード集

小老鼠
小老鼠オリジナル
2023-12-14 09:44:441870ブラウズ

JavaScript は、さまざまな動的でインタラクティブな Web ページ効果を作成するために使用できる非常に強力なプログラミング言語です。以下は、一般的な JavaScript 特殊効果のコード例です:

1. マウスオーバー効果

html
<!DOCTYPE html>  
<html>  
<head>  
 <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>  
</head>  
<body>  
 <div class="hover-effect"></div>  
</body>  
</html>

2. カルーセル効果

html
<!DOCTYPE html>  
<html>  
<head>  
 <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>  
</head>  
<body>  
 <div class="carousel">  
 <img src="image1.jpg" alt="Image 1">  
 <img src="image2.jpg" alt="Image 2">  
 <img src="image3.jpg" alt="Image 3">  
 <img src="image4.jpg" alt="Image 4">  
 </div>  
 <script>  
 var carousel = document.querySelector('.carousel');  
 var images = carousel.querySelectorAll('img');  
 var currentIndex = 0;  
 setInterval(function() {  
 images[currentIndex].style.display = 'none';  
 currentIndex = (currentIndex + 1) % images.length;  
 images[currentIndex].style.display = 'block';  
 }, 2000); // 每2秒切换一次图片  
 </script>  
</body>  
</html>

以上がJavaScript 特殊効果コード集の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。