arrange pictures in a row with a timed animation

In this scenario, I have a div containing multiple images lined up horizontally, with only the first image visible within the div. Currently, there are 5 images in total. The objective is to animate the images moving from right to left, eventually leaving the div and disappearing from the screen. Once all the images have completed their movement, the first image will come back into view (completing one full loop). To initiate this animation, you simply click a button.

The unique aspect of this animation is that at every odd numbered image, the motion pauses momentarily. For example, the sequence starts with image 1, moves on to image 2, then halts at image 3 for a few seconds before proceeding to image 4, pausing again at image 5, and finally returning to image 1 until the start button is pressed again.

What sets this setup apart is its scalability - it should be relatively easy to add more images to the sequence.

Here's what I currently have in terms of CSS / HTML:

<body>

<div id="container">


    <div id="fotos">
        <div class="image"><img src="afb_stuk/1.png"/></div>
        <div class="image"><img src="afb_stuk/2.png"/></div>
        <div class="image"><img src="afb_stuk/3.png"/></div>

        <div style="clear:both"></div>
    </div>



</div>
<div id="start">
    <h2 class="text"></h2>
</div>
</body>

And here's the corresponding CSS code:

body{
padding:0px;
margin:0px;
background-image:url(afb_stuk/background.jpg);
background-repeat:no-repeat;
background-size:cover;}

#container{
position:relative;
margin-left:50px;
margin-top:25px;
height:600px;
width:1250px;
border:solid thin red;
z-index:1;
/*overflow:hidden;}}

#fotos{
position:relative;
height:80%;
width:12000px;}

.image{
height:600px;
width:1250px;
float: left;}

.image img{
height:600px;
width:auto;}

#start{
position:relative;
margin:auto;
margin-top:-10px;
height:10px;
width:60px;
border-radius: 25px;
border: 2px solid #8AC007;
padding: 20px;}

.text{
margin-top:-10px;}

Answer №1

    <html>
    <head>
    <script>
    function start()
    {
    var y=1;
    var x=document.getElementById("image");
    setInterval(function(){check();},1000);
    function check()
    {
        if(y%2!=0)
            {
                setTimeout(function(){},3000);
            }
            x.src=''+(y%6)+'.jpg'+'';
        y++;
            if(y==6)
            start();
        }
    }
    </script>
    <style>
    body{
    padding:0px;
    margin:0px;
    background-image:url(afb_stuk/background.jpg);
    background-repeat:no-repeat;
    background-size:cover;}


    #container{
    position:relative;
    margin-left:50px;
    margin-top:25px;
    height:600px;
    width:1250px;
    border:solid thin red;
    z-index:1;
    /*overflow:hidden;*/}


    #fotos{
    position:relative;
    height:80%;
    width:12000px;}


    .image{
    height:600px;
    width:1250px;
    float: left;
    }

    .image img{
    height:600px;
    width:auto;}
    </style>
    </head>
    <body>

    <div id="container">
        <div id="fotos">
            <div class="image">
                <img src="1.jpg" id="image"/>
            </div>
        </div>
    </div>
    <button onclick="start()" id="new">Click to start!</button> 
    </div>
    </body>
    </html>

Ensure your image names are labelled as 1, 2, 3, 4.jpg etc. and experiment with delaying the transition between images.

Answer №2

After discovering a helpful YouTube tutorial with a fiddle, I decided to customize some of the effects and image width to achieve the desired outcome. Thanks to everyone who assisted me :) [1]http://jsfiddle.net/EjZzs/15/

$(function() {

//slider configuration
var width = 720;
var animationSpeed = 1000;
var pause = 3000;
var currentSlide = 1;

//DOM element caching
var $slider = $('#slider');
var $slideContainer = $('.slides', $slider);
var $slides = $('.slide', $slider);

var interval;

function startSlider() {
    interval = setInterval(function() {
        $slideContainer.animate({'margin-left': '-='+width}, animationSpeed, function() {
            if (++currentSlide === $slides.length) {
                currentSlide = 1;
                $slideContainer.css('margin-left', 0);
            }
        });
    }, pause);
}
function pauseSlider() {
    clearInterval(interval);
}

$slideContainer
    .on('mouseenter', pauseSlider)
    .on('mouseleave', startSlider);

startSlider();

});

[2]https://youtu.be/KkzVFB3Ba_o

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

The arrangement of CSS code is crucial for it to work properly; any deviation from the correct order

I am facing a problem where I am trying to display a circular div using CSS, but it only works if the background image property is set first. Typically, this wouldn't be an issue if the image wasn't being dynamically inserted using PHP code. I ...

Dealing with form submission issues in jQuery and jqGrids

Lately, I've been experimenting a lot with jqgrids and have almost everything set up the way I want it - from display to tabs with different grids. Now, I'm trying to utilize Modals for adding and editing elements on my grid. The issue I'm ...

Tips for creating an onChange function in an input field using jQuery

I am looking to dynamically create inputs where each input has an `onChange` function with a variable. Here is my code: var distinct_inputs = 0; $('.icon1').click( function(){ distinct_inputs = distinct_inputs + 1 ; $('#insert-file&apo ...

Decrease the font size of text using intervals in CSS

I'm facing a challenge where I need to decrease the font size by 10% every 2 seconds. <div class="shrink"> text </div> .shrink{ transition: 2s linear all; font-size : 20px; } Is there a way to achieve this using only CSS? ...

Stop input-group-append from causing adjacent input-groups to shift right

When I have two input fields next to each other and render a button within an input group, the button pushes the neighboring input field on the right, decreasing its width. This behavior can be observed in this example sandbox: view code sample. To illus ...

Issues with Angular-Trix compatibility with Internet Explorer 10

I am currently using the Angular-trix rich text editor, which is functioning perfectly in all browsers including IE 11. However, I am encountering issues with it not working in IE10 or earlier versions. An error message that keeps appearing states: Una ...

I'm curious about how I can apply @media queries given that certain phones possess higher resolution than computers

There seems to be a common recommendation to utilize @media queries for adjusting CSS based on whether the user is on mobile or not. However, I'm a bit confused because my phone has a width of 1440p while my computer has 1920p. Should I consider apply ...

The absence of an eye icon in the password field when using bootstrap 5

I'm having trouble positioning the eyeball icon to the right side of my form when using Bootstrap v5 and FontAwesome v5. Instead, the password field is being shifted further to the right compared to the username field, and the eye icon is not displayi ...

The appearance of CSS output is noticeably distinct between iPhones and personal computers

My issue is with the development of my website. When I access it on my PC, everything looks fine. However, when I try to visit the site on my iPhone, there is a noticeable difference in the output. The space above the navigation bar appears differently whe ...

Modifying images through resizing and scaling within a flexible web application to accommodate different screen dimensions

With my web application, I have an image that changes in sizes as it calls a different image from the database each time it is viewed. My goal is to make sure this image is displayed responsively on different devices. For smartphones, I want the image to f ...

The issue with Ajax functionality seems to be limited to affecting only the first element within the Bootstrap

I have implemented Bootstrap modal and Ajax to submit my Booking Form for different Products. The Ajax submission works fine for the first Product, but when trying to submit the form for other Products, it redirects to a 404 Error Page. I have spent hours ...

Conceal Class When Input Value is "X"

Is there a way to dynamically hide a specific seller (<div class="seller">) from a table using CSS and PHP based on a get parameter? Each seller has a unique ID represented by <input type="hidden" value="1" name="seller_id">. For example, if I ...

How can you modify the color of a FontAwesome icon?

I am currently utilizing BigCommerce and my code looks like this: .icon-cart { color: #4ca3c0 !important; } .icon-cart a{ color: #4ca3c0 !important; } Despite the above, it seems that the icon's color remains unchanged. Any suggestions or i ...

Loading jQuery on document ready with an Ajax request can lead to slow loading times

My current project involves a significant number of ajax requests being made on document.ready. Additionally, I have ajax requests for every database transaction. These requests are all managed in a JS file, with each ajax request corresponding to a PHP pa ...

Is it possible to create a dynamic jQuery dialog that appears after appending data without the need to reload the

I'm currently dealing with a situation where a page houses a massive table within a CRUD interface. Each link within a span activates a jQuery UI Dialog Form that pulls its content from another page. After completing an action, such as creating a new ...

Mistake in labeling a checkboxgroup in ExtJs4.2 by wrapping a boxLabel incorrectly

I am encountering an issue where the box labels of the checkboxes are wrapping under the checkbox: http://jsfiddle.net/6pYWh/ { xtype: 'checkboxgroup', columns: 1, vertical: true, items: [ ...

Style the CSS elements for a specific item

I have a situation where I need to change the background image of a specific element within a CSS class without affecting others. For example, I have a class "a" with a background image that is used for multiple elements, but I only want to change the back ...

Creating a dynamic background image with automatic cropping techniques: How to do it?

I'm currently working on a custom wordpress theme and I've encountered an issue that I need help with. I want to have a wide background image on my homepage with text centered on it, but I also want the height to remain the same as the browser w ...

Can anyone share tips on implementing animations during transitions when using $location.path for redirection in AngularJS?

In my project setup, I am utilizing AngularJS for the structure and backend functionalities, while JqueryM is being used for the UI design elements. Currently, I'm redirecting using $location.path with ng-click. Is there a method to incorporate JQM d ...

"A validation error occurred in the ABC Ajax request in an Asp.net application due to invalid

Here is my script: <script type ="text/javascript"> $(document).ready(function () { $('#<%=Button1.ClientID %>').click(function () { var ABC = 'TEST'; $.ajax({ type: ...