Creating a dynamic Image Gallery with the power of JavaScript and HTML5

I have been working on creating an image slideshow using a combination of Java Script and HTML 5. The issue I am running into is that the ImageSlider function is only being called once when I use the SetInterval() method to call it repeatedly.

Below is the code snippet:

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Online Booking</title>
</head>
<style>
iframe
{
display:block;
float:middle;
margin: 0 auto;
text-align: center
}
</style>
<body onload="init()">
<script>
function init()
{           
setInterval(imageSlider(),5000);
}
function staticVar()
{

if (staticVar.counter == undefined)
{
    staticVar.counter = 1
}
else
{
    staticVar.counter++
}
return staticVar.counter;
}
function imageSlider()
{
alert("sl");
var j= staticVar();     
var imgArray = new Array();
imgArray[0] = new Image();
imgArray[0].src = '91.jpg';

imgArray[1] = new Image();
imgArray[1].src = 'myBro.jpg';

imgArray[2] = new Image();
imgArray[2].src = 'me.jpg';

document.getElementById("imageSlide").src = imgArray[j].src;
}
</script>
<iframe height="580" width="25%" src="91.jpg" id="imageSlide"> </iframe>
</body >
</html>

Answer №1

Ensure to utilize

setInterval(imageSlider,5000);

rather than

setInterval(imageSlider(),5000);

For more information, refer to the setInterval() documentation.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

HTML5's drag-and-drop feature, including nested targets, allows for intuitive and interactive user

I'm currently implementing HTML5 drag and drop functionality. I have a parent div that is droppable, and inside it, there is another child div that is also droppable. <div id="target-parent"> <div id="target-child"></div> </d ...

IE disregard min-height property of flex container

After researching, it appears that using the standardized flex terms should work with IE10/IE11. I have a container div with 2 child divs. Both child divs are smaller than 400px, so there should always be enough space for the justify-content: space-betwe ...

A guide on transferring documents between collections using Mongoose and MongoDB

I have a list of tasks that includes both completed and incomplete items. Additionally, I have two buttons - one for deleting an item (which is functional) and the other for marking an item as done or not. I am struggling with creating a function to move ...

Is it possible for me to add images to the input file individually before submitting them all at once?

When images are inserted one by one, the 'input file' only reads one picture at a time. However, when images are inserted in multiple quantities, the result is displayed for each image that the user inputs. window.onload = function() { //Ch ...

Getting a specific nested child component from the parent component's slot in the render function: A step-by-step guide

I have successfully implemented conditional rendering of a child component using the render function. Below is an example of the parent component with the child component: <Parent :index="1"> <Child> ... </Child> <Child&g ...

Utilize parameters in specified file in node.js

Currently, I am attempting to send variables to a file that I have imported in node.js in order to utilize them within that specific file. var myname = "Adnan"; var incfile = require('./ex.js'); My main goal is to access the myname variable wit ...

Unit tests are successful, but an error occurs stating "headers cannot be set after they have been sent."

Currently, I am working on writing unit tests for the API endpoints of my very first express app. I am using a data structure as a placeholder for a database and all the tests are passing successfully. However, I encountered an error in the console stating ...

Creating a polished look with CSS through rounded font edges

Can CSS be used to create rounded edges on a font? I'm looking for an effect similar to the smooth edges in Photoshop https://i.sstatic.net/w4Zd4.jpg I attempted using an SVG filter, but found it quite complex. Is there a simpler method? Here is ...

Is there a more efficient alternative to the sluggish scroll event?

Currently, I have set up a scroll event that tracks the user's position on the page and updates the navigation styling based on which section they are viewing. However, the calculation I'm using during scrolling is quite resource-intensive and ca ...

Absence of environment variables in getServerSideProps within Next.js 13 independent deployment

Currently, I'm facing an issue where the props of my pages are not being hydrated properly. This problem arises as I migrate from an older version of NextJS and is where I find myself stuck at the moment. While everything seems to be working fine in d ...

If the value of grid-column-end exceeds the maximum number of columns in a CSS grid, what will occur?

I have been delving into the CSS grid system with insight from MDN. In the segment on line based placement, after experimenting a bit, I came across an unusual behavior. When the layout consists of two columns, for example defined as grid-template-columns: ...

The Highchart formatter function is being called twice on each occasion

My high chart has a formatter function that seems to be running twice. formatter: function() { console.log("starting formatter execution"); return this.value; } Check out the Fiddle for more details! ...

What is the best way to identify duplicate data being returned from a server within a for loop?

When receiving sorted data from the server through an infinite scroll, my goal is to filter out duplicate entries and add new unique data to a client-side array. If duplicates are found, I want to stop the infinite scrolling process. $scope.collections = ...

Validate account existence in Angular 2 before account creation

I am currently subscribing to the following event list and attempting to implement additional checks before completion. userService.createUser(this.form).subscribe((user)=>{ this.user = user }) Here is the service method in question: createAccount(us ...

Is there a way to prevent undefined properties when using .each in jQuery with a JSON object?

I am trying to populate the values of <inputs> on a webpage using data from a JSON object. http://codepen.io/jimmykup/pen/exAip?editors=101 To begin, I create a JSON object with two values - one for name and one for url. var jsonObj = []; var nam ...

Is it necessary to add .html files to the public assets folder?

Currently, I am developing a web application using Node.js and Express. Typically, the views are stored separately from the public folder to account for dynamic content when utilizing Jade templating. However, if my .html files will always remain static, ...

Implementing a permanent class following an incident

Is it possible to dynamically add a class to an element when an event occurs rather than based on a condition? For example, I have a td that displays a variable. <td>{{myVar}}</td>//myVar=10 When the variable changes to myVar=15, I want to ad ...

HTML table with two rows of cell pairs

Is it possible to achieve the layout shown in this screenshot using an HTML table? I am aware that I can use <div> for this, but I would prefer to maintain the table formatting. https://i.sstatic.net/ESZkn.png ...

How can one retrieve the x and y coordinates from the client's browser and pass them to the server in a Bokeh server setup?

I'm currently working on a Bokeh server app called getcoords.py. To start the server, I use the command: bokeh serve getcoords.py. The app includes a HoverTool with a CustomJS callback function and a quad glyph configured to trigger a selected event o ...

What is the best way to set a specific height for a centered image in jQuery LightSlider?

I am faced with a light slider displaying images of varying heights. When I enable isAdaptiveHeight, it adjusts the height based on the image size automatically, but this doesn't meet my preferences. What I desire is to set a fixed height for all ima ...