Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- 7. Implement a jQuery script to create a simple slideshow that automatically cycles through images stored in an array. -->
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <script src="https://code.jquery.com/jquery-3.7.1.min.js"
- integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
- <title>Document</title>
- </head>
- <body style="background-image: url();">
- <script>
- $(document).ready(function () {
- const arr = ["./images/img1.jpg", "./images/img2.jpg", "./images/img3.jpg", "./images/img4.jpg", "./images/img5.jpg"];
- let i = 0, intv = 2000;
- function changeBg() {
- $('#imageChng').attr("src", arr[i]);
- i = (i + 1) % arr.length;
- }
- changeBg();
- setInterval(changeBg, intv);
- });
- </script>
- <img src="" id="imageChng" style="height: 100vh; width: 100vw;">
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement