JavaScript - Automatic Image Slider
Submitted by razormist on Thursday, October 10, 2019 - 12:56.
In this tutorial we will create a Automatic Image Slider using JavaScript. This code will automatically play the animated image slideshow when the user open the application. The code will automatically animate the image within a set of duration using setInterval() by incrementing the array index position of an image to freely change the image alternately. Feel free to modify and apply it in your system, this is a user-friendly kind of program
We will be using JavaScript as a server-side scripting language because It gives a greater control of your web page and extend its capability in a modern way approach. It is written in HTML or as an external sourcing to add some necessary features in your website.
There you have it we successfully created a Automatic Image Slider using JavaScript. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!
Getting started:
First you have to download bootstrap framework, this is the link for the bootstrap that I used for the layout design https://getbootstrap.com/.The Main Interface
This code contains the interface of the application. To create this just write these block of code inside the text editor and save this as index.html.- <!DOCTYPE html>
- <html lang="en">
- <head>
- <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
- <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
- </head>
- <nav class="navbar navbar-default">
- <div class="container-fluid">
- </div>
- </nav>
- <body>
- <div class="col-md-6 well">
- <hr style="border-top:1px dotted #ccc;"/>
- <div class="row">
- </div>
- </div>
- </body>
- </html>
Creating the Script
This code contains the script of the application. This code will automatically change the image. To do this just copy and write these block of codes inside the text editor, then save it as script.js inside the js folder.- var image = new Array("images/image1.jpg", "images/image2.jpg", "images/image3.gif");
- var count = 0;
- var length = image.length - 1;
- function imageSlider(index){
- count = count + index;
- if(count > length){
- count = 0;
- }
- if(count < 0){
- count = length;
- }
- document.slideshow.src = image[count];
- return false;
- }
- autoSlideShow();
- function autoSlideShow(){
- setInterval("imageSlider(1)", 4000);
- }
Add new comment
- 1101 views