All TalkersCode Topics

Follow TalkersCode On Social Media - A Social Media Network for developers Join Now ➔

Pause And Resume Image SlideShow Using jQuery

Last Updated : Jul 1, 2023

IN - jQuery | Written & Updated By - Riya

In this tutorial we will show you how to pause and resume image slideshow or i can say any slideshow using this method using jQuery, Image slideshow is the best way to display multiple images efficiently and effectively.

Sometimes user wants to control the slideshow like to pause the slideshow, resume the slideshow, go to the previous or next slide etc.

You may also like Basic Image Slideshow With Previous And Next Button Using jQuery

Pause And Resume Image SlideShow Using jQuery

To Create Notification Bar It Takes Only Three Steps:-

  1. Make a HTML file and define markup for slideshow
  2. Make a js file and define scripting for slideshow
  3. Make a CSS file and define styling for slideshow

Step 1. Make a HTML file and define markup for slideshow

We make a HTML file and save it with a name slideshow.html

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="slideshow_script.js"></script>
<link rel="stylesheet" type="text/css" href="slideshow_style.css">
<div id="wrapper">
 <input type="button" value="Resume SlideShow" onclick="start_slideshow();">
 <input type="button" value="Pause SlideShow" onclick="pause_slideshow();">
 <div id="image_div">
  <img src="images/image1.jpg">
 <input type="hidden" id="image_no" value=1>

In this step we made two buttons to resume and pause slideshow and then we create a div which hold our image and then we create hidden fields which is used to holds image number we initialise this to 1 because we already display first image and want to display 2nd image as per the image array we were going to made in our second step.

You may also like Content Slider Using jQuery And CSS

Step 2. Make a js file and define scripting for slideshow

We make a js file and save it with a name slideshow_script.js


var interval;

function start_slideshow()
 var images = ["image1" , "image2" , "image3" , "image4"];
  var img_no=document.getElementById("image_no").value;
   document.getElementById("image_div").innerHTML="<img src='images/"+images[img_no]+".jpg'>";
 }, 3000);

function pause_slideshow()

In this step we made two functions to pause and resume slideshow whenever user clicks on their respective buttons.

In this step we use document.ready function to start the slideshow just after page load and define a variable called interval to clear the intervals to prevents any function collision generally used with setInterval functions.

In first function we first clear all the interval to prevent any function collisions and then we insert images name in image array and use setInterval function to display the next image in every 3 seconds.

Under the setInterval function we get the value of image_no to know what image is going to display then we use jQuery fadeout effect to display the image.

Then if image_no is equal to 3 it means that this is our last image according to array because we use 4 images in array and array index starts from 0 so if the image_no value is 3.

We set the value of image_no to 0 to continue the slideshow from first image it works like a image loop and if the value is not equal to 3 the we just simply increment the image_no value by 1.

In our second function that is pause_slideshow() function we simply use clearInterval method to pause the slideshow.

You may also like Basic Image Gallery With Image Preview Using jQuery

Step 3. Make a CSS file and define styling for slideshow

We make a CSS file and save it with a name slideshow_style.css

 margin:0 auto;
 margin:0 auto;
 border:1px solid #F5D0A9;

Thats all, this is how to Pause and Resume Image SlideShow using jQuery. You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.

I hope this tutorial on Pause and Resume Image SlideShow using jQuery helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Riya

A recent graduate with a Bachelor of Technology (B.Tech) in Computer Science from India. She is passionate about leveraging technology to solve real-world problems. With a strong foundation and experience in programming languages such as Python, Django, HTML, CSS, and JavaScript, java, php and have honed her skills through hands-on projects and coursework.

Follow Riya On Linkedin 🡪