SuperiorRat
Framework Developer
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
200 XP
In this tutorial we will create a Simple Slideshow using Javascript. JavaScript is a scripting or programming language that allows you to implement complex things on web pages. It is widely used in designing a stunning website. It is an interpreted programming language that has a capabilities of Object-Oriented. So Let's do the coding.
Before we started:
This is the link for the bootstrap that has been used for the layout of the calculator https://getbootstrap.com/.
The Main Interface
This code contains the interface of the application. This code will display the image within the javascript function. To create this just write these block of code inside the text editor and save this as index.html.
Creating the Script
This code contains the script of the application. This code will try to select different images from the source folder everytime the button is clicked. To do this just copy write the code as shown below inside the text editor and save it as slideshow.js.
There you have it we successfully created a Simple Slideshow 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!!!
Download
Before we started:
This is the link for the bootstrap that has been used for the layout of the calculator https://getbootstrap.com/.
The Main Interface
This code contains the interface of the application. This code will display the image within the javascript function. 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"
>
- <a
class
=
"navbar-brand"
href
=
"https://sourcecodester.com"
>
Sourcecodester</
a
>
- </
div
>
- </
nav>
- <body
>
- <div
class
=
"col-md-3"
></
div
>
- <div
class
=
"col-md-6 well"
>
- <h3
class
=
"text-primary"
>
Javascript - Simple Slideshow</
h3
>
- <hr
style
=
"border-top:1px dotted #ccc;"
/
>
- <center
><img
src
=
"images/pic1.jpeg"
name
=
"slideshow"
height
=
"400px"
width
=
"500px"
></
center
>
- <center
>
- <button
onclick
=
"SetAuto()"
class
=
"btn btn-success"
><span
class
=
"glyphicon glyphicon-repeat"
></
span
>
Auto</
button
>
- <button
onclick
=
"ChangeImage(-1)"
class
=
"btn btn-primary"
><span
class
=
"glyphicon glyphicon-arrow-left"
></
span
></
button
>
- <button
onclick
=
"ChangeImage(1)"
class
=
"btn btn-primary"
><span
class
=
"glyphicon glyphicon-arrow-right"
></
span
></
button
>
- </
center
>
- </
div
>
- </
body
>
- <script
src
=
"slideshow.js"
></
script
>
- </
html
>
Creating the Script
This code contains the script of the application. This code will try to select different images from the source folder everytime the button is clicked. To do this just copy write the code as shown below inside the text editor and save it as slideshow.js.
- var
image =
new
Array
(
"images/pic1.jpeg"
,
"images/pic2.jpeg"
,
"images/pic3.jpg"
,
"images/pic4.jpg"
)
;
- var
count =
0
;
- var
length =
image.length
-
1
;
- function
ChangeImage(
num)
{
- count =
count +
num;
- if
(
count >
length)
{
- count =
0
;
- }
- if
(
count <
0
)
{
- count =
length;
- }
- document.slideshow
.src
=
image[
count]
;
- return
false
;
- }
- function
SetAuto(
)
{
- setInterval(
"ChangeImage(1)"
,
4000
)
;
- }
There you have it we successfully created a Simple Slideshow 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!!!
Download
You must upgrade your account or reply in the thread to view the hidden content.