Search

_0319_종합예제10

대분류
STEP03 이벤트
소분류
이벤트

영상

개념

<!DOCTYPE html> <html lang="ko"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> #slider { margin: 0 auto; border: 1px solid black; } .moveIcon { width: 50px; height: 50px; font-size: 25px; background-color: white; border-style: none; cursor: pointer; } .product { width: 100px; } </style> </head> <body> <table id="slider" border="1"> <tr> <td> <button class="moveIcon" onclick="left()"><</button> </td> <td> <img class="product" src="images/1.png"> </td> <td> <img class="product" src="images/2.png"> </td> <td> <img class="product" src="images/3.png"> </td> <td> <button class="moveIcon" onclick="right()">></button> </td> </tr> </table> <script> let list = ["1.png", "2.png", "3.png", "4.png", "5.png"]; function left() { let hello = document.getElementById("hello"); let temp = list[list.length - 1]; for(let i=list.length - 1; i>0; i--) { list[i] = list[i - 1]; } list[0] = temp; let products = document.querySelectorAll(".product"); for(let i=0; i<list.length; i++) { products[i].src = "images/" + list[i]; } } function right() { // temp = "1.png" let temp = list[0]; for(let i=0; i<list.length - 1; i++) { list[i] = list[i + 1]; } list[list.length - 1] = temp; // ["2.png", "3.png", "4.png", "5.png", "1.png", ] let products = document.querySelectorAll(".product"); for(let i=0; i<products.length; i++) { products[i].src = "images/" + list[i]; } } </script> </body> </html>
Java
복사