• We just launched and are currently in beta. Join us as we build and grow the community.

Javascript - Simple Slideshow

SuperiorRat

Framework Developer
S Rep
0
0
0
Rep
0
S Vouches
0
0
0
Vouches
0
Posts
85
Likes
137
Bits
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.
  1. <!DOCTYPE html>
  2. <html

    lang

    =

    "en"

    >
  3. <head

    >
  4. <link

    rel

    =

    "stylesheet"

    type

    =

    "text/css"

    href

    =

    "css/bootstrap.css"

    /

    >
  5. <meta

    charset

    =

    "UTF-8"

    name

    =

    "viewport"

    content

    =

    "width=device-width, initial-scale=1"

    /

    >
  6. </

    head

    >
  7. <nav class

    =

    "navbar navbar-default"

    >
  8. <div

    class

    =

    "container-fluid"

    >
  9. <a

    class

    =

    "navbar-brand"

    href

    =

    "https://sourcecodester.com"

    >

    Sourcecodester</

    a

    >
  10. </

    div

    >
  11. </

    nav>
  12. <body

    >
  13. <div

    class

    =

    "col-md-3"

    ></

    div

    >
  14. <div

    class

    =

    "col-md-6 well"

    >
  15. <h3

    class

    =

    "text-primary"

    >

    Javascript - Simple Slideshow</

    h3

    >
  16. <hr

    style

    =

    "border-top:1px dotted #ccc;"

    /

    >
  17. <center

    ><img

    src

    =

    "images/pic1.jpeg"

    name

    =

    "slideshow"

    height

    =

    "400px"

    width

    =

    "500px"

    ></

    center

    >
  18. <center

    >
  19. <button

    onclick

    =

    "SetAuto()"

    class

    =

    "btn btn-success"

    ><span

    class

    =

    "glyphicon glyphicon-repeat"

    ></

    span

    >

    Auto</

    button

    >
  20. <button

    onclick

    =

    "ChangeImage(-1)"

    class

    =

    "btn btn-primary"

    ><span

    class

    =

    "glyphicon glyphicon-arrow-left"

    ></

    span

    ></

    button

    >
  21. <button

    onclick

    =

    "ChangeImage(1)"

    class

    =

    "btn btn-primary"

    ><span

    class

    =

    "glyphicon glyphicon-arrow-right"

    ></

    span

    ></

    button

    >
  22. </

    center

    >
  23. </

    div

    >
  24. </

    body

    >
  25. <script

    src

    =

    "slideshow.js"

    ></

    script

    >
  26. </

    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.
  1. var

    image =

    new

    Array

    (

    "images/pic1.jpeg"

    ,

    "images/pic2.jpeg"

    ,

    "images/pic3.jpg"

    ,

    "images/pic4.jpg"

    )

    ;
  2. var

    count =

    0

    ;
  3. var

    length =

    image.length

    -

    1

    ;

  4. function

    ChangeImage(

    num)

    {

  5. count =

    count +

    num;

  6. if

    (

    count >

    length)

    {
  7. count =

    0

    ;
  8. }

  9. if

    (

    count <

    0

    )

    {
  10. count =

    length;
  11. }

  12. document.slideshow

    .src

    =

    image[

    count]

    ;

  13. return

    false

    ;
  14. }

  15. function

    SetAuto(

    )

    {
  16. setInterval(

    "ChangeImage(1)"

    ,

    4000

    )

    ;
  17. }

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.
 

452,496

337,656

337,664

Top