Animated presentation with Java Script

I am looking to create a slideshow with animation. I want there to be a delay of 1-2 seconds before each transition, or change in image, after the animation is completed. How can I achieve this?

<html>
    <style>
        #slideshow{width:310;height:210;border-style:solid;}
        #imge{
            position:absolute;left:15;top:15;
            animation:myfirst 5s;
            animation-iteration-count:infinite;
            -webkit-animation:myfirst 5s; 
            -webkit-animation-iteration-count:infinite;
        }
        
        @keyframes myfirst
        {
            from {width:0;}
            to{width:300;}
        }

        @-webkit-keyframes myfirst /* Safari and Chrome */
        {
            from {width:0;}
            to {width:300;}
        }

    </style>
    
    <body>
        <div id="slideshow">
            <img id="imge" src="img1.jpg" height="200" width="300"/>
        </div>
        
        <script>
            var count=1;

            mf();

            function mf(){

                document.getElementById("imge").src="img"+count+".jpg";

                if(count<3)
                    count++;
                else
                    count=1;

                setTimeout("mf()",5000);
            }
        </script>
        
    </body>
</html>

Answer №1

<script>
var counter = 0;
slideshow();
function slideshow()
{

document.getElementById("imge").src = "img" + counter + ".jpg";

if(counter == 3)
{
  setTimeout("slideshow()", 8000);
}else{
if(counter < 3)
counter++;
else
counter = 1;
setTimeout("slideshow()", 5000);

}}
</script>

It would be more effective to create the slideshow using only CSS3 or utilize the overflow CSS property for creating a slideshow in JavaScript.
Check out this example of a CSS3 slideshow This resource was very helpful for me in designing my game map similar to Google Maps. I highly recommend exploring this link to understand the process of creating animations on the web.

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

Updating the jQuery datatable with new data after a page switch or another action

One of the features on my page is a jQuery datatable that I populate with data using the following script: $(document).ready(function () { var dataTable; $(document).on("click", ".myBtnClass", function () { if (dataTable != null) ...

Unable to view sidebar navigation on the screen

I've been experimenting with the sidebar navigation from w3 schools, specifically trying to create a side-nav that opens from one div. You can see an example here: http://www.w3schools.com/w3css/tryit.aspfilename=tryw3css_sidenav_left_right&stack ...

Ways to implement callbacks in various functions within JavaScript

Having trouble figuring out how to access a variable inside a callback function from another function located outside of the callback... To simplify the issue: There is a function that retrieves JSON data from the web with some predefined arguments. Upon ...

Tips for adjusting the time interval on an automatic slideshow when manual controls are in play

I'm having trouble with my slideshow. I want it to run automatically and also have manual controls, but there are some issues. When I try to manually control the slides, it takes me to the wrong slide and messes up the timing for the next few slides. ...

Incorporating personalized CSS styles into a Bootstrap 4 card

I have been scouring through countless questions and solutions on StackOverflow, but nothing seems to be working for me. While p-5 is doing its job just fine for padding, it applies to all devices. I am in need of specific CSS for mobile devices when it co ...

React-image carousel

I've been attempting to create a photo/video carousel using the resource found at The desired result should resemble this, complete with a modal: https://i.sstatic.net/GAdPJ.jpg I've tried following the provided code snippet, but it doesn' ...

The script ceased functioning immediately following the inclusion of a case-insensitive search feature and interactive images

In the process of creating my inaugural project featuring a collection of images, I wanted to include a filter/search bar at the top. This bar would dynamically filter the displayed pictures based on user input. For example, typing "Aatrox" into the search ...

Issue in TypeScript where object properties may still be considered undefined even after verifying using Object.values() for undefined values

I'm encountering an issue with TypeScript regarding my interface MentionItem. Both the id and value properties are supposed to be strings, but TypeScript is flagging them as possibly string | undefined. Interestingly, manually checking that id and va ...

Creating a dynamic line in Three.js that connects the closest vertices from two models

I am facing a challenge with loading two models into a scene using OBJloader and the Three.JS library. Some of the models are billboarded by using model.setRotationFromQuaternion( camera.quaternion ); My main objective is to create lines connecting a vert ...

Error encountered when attempting to upload image on Twitter: missing media parameter

According to the latest Twitter media upload API documentation, it is recommended to first utilize either POST multipart/form-data or base64 encoded files when interacting with . However, encountering an error with code 38 stating "media parameter is mi ...

Issues with aligning Bootstrap columns

I'm currently in the process of developing a website that interfaces with the Twitch API to display which users, from a predetermined group of 7, are online and offline. The functionality is mostly there, but I'm facing an issue where the top div ...

Using PHP to convert user input from an HTML form into an SQL file within the current folder (Inquiry)

I am seeking an alternative method to create a database without using myphpadmin or MySQL. I have been encountering difficulties in setting them up. Is there a simpler approach where I can use a .html file with a form and PHP code to collect user input and ...

guide for interpreting a complex json structure

I'm attempting to extract data from a JSON file that has multiple layers, like the example below. - "petOwner": { "name":"John", "age":31, "pets":[ { "animal":"dog", "name":"Fido" }, ...

Using the data of multiple locations within a for loop to create Leaflet markers for use in a click event

I am currently working on a leaflet map that showcases markers for the top cities in a selected country. The locationList array consists of objects with city information such as latitude, longitude, and cityName. These values are utilized to place markers ...

JavaFX text label does not adjust its font according to the CSS file

In my FXML file, the structure is as follows: ... <BorderPane id="header"> <right> <Label styleClass="title" text="A Label" /> </right> </BorderPane> ... I also have a CSS file with the following content: #h ...

Discover the technique for splitting a string using jQuery with multiple strings as separators

I am looking to split a string in jQuery or JavaScript using multiple separators. When we have one string as a separator, our code looks like this: var x = "Name: John Doe\nAge: 30\nBirth Date: 12/12/1981"; var pieces = x.split("\n"), p ...

What could be causing the issue with object-fit not functioning properly within a container with a max

My goal is to insert a video into a container that has a width of 100% and automatically adjusts its height while maintaining the aspect ratio, but with a maximum height set. I want the video to completely fill the container even if some parts are cropped ...

Copy the value of a selected textbox to another using JQuery Auto Complete

I'm currently facing an issue where I need to assign one textbox's selected value to another textbox. Upon checking in the Firefox Browser Console, I've realized that the state variable (c_search.php?state) is not holding any value. Could s ...

A date picker pops up when the user clicks on an Angular input field of type text

I am looking to edit a dateTime value using Angular/Ionic, but unfortunately there is no dateTime picker available. To work around this issue, I have split the field into separate date and time fields. In order to incorporate placeholder text and format th ...

How to use Angular ng-repeat to filter an array by a specific key

Here is the data I am working with: $scope.allNames = [ "A": [ { "name": "a1" }, { "name": "a2" }, { "name": "a3"} ], "B": [ { "name": "b1" }, { "name": "b2" }, { "name": "b3"} ], "C": [ { "name": "c1" }, { "name": "c2" }, { "name": "c3"} ], ...