Utilize various animations on multiple background images within a singular class

I have a unique situation where I am using a single class called slider, but I need different types of animations for various images. Can someone please assist me in implementing this? Currently, all my images are using the same animation style, but I would like to maintain the single class slider.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    

    <title>Document</title>
    <style>
       body{
           margin:0p;
           padding:0p;
          background: green;
          perspective: 800px;
          height: 100vh;
   width: 100wh;
       
       }
        .slider{
        /*    background-image: url(https://www.mozilla.org/media/img/logos/firefox/logo-quantum.9c5e96634f92.png);
  background-size: 800px 800px;
  width: 800px;
  height: 800px;
  border: 2px solid;
  color: pink;
         */
        width:100vw;
         height:100vh;
            background: url(b1.jpg);

  background-size: 100wh 100vh;   
 /* animation: slide 2s infinite;*/
  animation: slide 
   2s infinite;                                                   
  margin: 100px auto;
         
        }
    @keyframes slide{
        from{
           /* transform:rotateY(0deg);*/
          /* transform: rotate3d(1, 1, 1, 0deg);*/
           transform: rotate3d(0, 1, 0, 0deg);
  background-color: pink;
        }
        to{
           /* transform:rotateY(180deg); 
            transform: rotate3d(1, 1, 1, 360deg);*/
            transform: rotate3d(0, 1, 0, 360deg);
  background-color: pink;
        }  
      
            25%{
                background-image: url(b2.jpg);
               
 
                background-size: 100wh 100vh;   
 
            }
            50%{
                background-image: url(b3.jpg);
                

                background-size: 100wh 100vh;   
            }
            75%{
                background-image: url(b4.jpg);
                

                background-size: 100wh 100vh;     
            }
            100%{
                background-image: url(b5.jpg);
                

                background-size: 100wh 100vh;    
            }

        }
    </style>
</head>
<body>
   <div class="slider"></div>
</body>
</html>

Here is the fiddle

My fiddle

In addition, I have noticed that each image displays a repetition effect, making it appear as if the image is being reduced and added again. Is there a way to display each image without repetition at 100% view?

Any assistance on this matter would be greatly appreciated.

Answer №1

Understanding the concept of a slider, it appears that the intention is to rotate a series of images sequentially within a single animation rather than employing distinct animations for each image. This can be accomplished as long as the desire is not to have completely different animations for each 'slide'.

Here are a few key points: It is reasonable to question why the image is repeated, which is due to the default background setting in CSS. To prevent these extra elements from appearing, adjust it to 'no-repeat'.

The images may possess varying aspect ratios compared to the viewport's dimensions (used by the containing element). To ensure visibility of the entire image or cover the entire viewport, utilize background-size: contain or cover, respectively. Depending on your preference and the images' aspect ratios, experiment with both options.

For better positioning, consider centering the background-position both horizontally and vertically instead of the default left and top alignment.

An adjusted code snippet has been provided below with transition effects between image changes, which can be fine-tuned based on preferences. Pay attention to the percentage settings in the keyframes section to ensure all images are showcased properly.

UPDATE In the revised snippet, individual animations are assigned to each image while adhering to the single slider class requirement. Each image is granted a segment of the overall animation time allocation. Custom animations like rotation, zooming, etc., are defined for each slide within their respective keyframe sections.

Four slides have been incorporated in this snippet, each receiving a specific animation treatment during one iteration of the sequence. The timings specified allow for dynamic movement paired with a static display phase for each image. Additional images and diverse animations can be added by adjusting the percentages in the keyframes section and inserting more background images accordingly.

Note: Opacity adjustments impact the entire element, including background colors, so modifications may be required to achieve the desired visual effect.

Experimentation with opacity and transform properties may be essential to avoid abrupt transitions between images. While duplicating transformation and opacity settings in every instance is not always mandatory, it serves as a helpful reminder that each transformation should include all necessary parameters.

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

Using HTML or JavaScript to generate a multitude of identical HTML elements on a webpage

I am currently designing a page that requires the presence of numerous tree illustrations with leaves, spanning across the width at the bottom of the page. I have considered two methods to achieve this. One option is to create a single set of trees and lea ...

What's causing the misalignment in the top row?

What could be causing the misalignment of cells in the first row? JSfiddle link Here is the code snippet: .box3 { margin: auto; width: auto; height: 300px; } .tb2 { border-collapse: collapse; color: black; text-align: center; ma ...

What is a more efficient method for writing HTML in JavaScript compared to document.write?

A helpful JavaScript code snippet for a jQuery mobile app can be found here. After finding it, I made some slight adjustments to suit my needs. Being a beginner in JavaScript and currently taking a course on Codecademy, I recently learned that document.wr ...

Show the table in a vertical orientation with HTML and CSS

I am currently tackling a project that involves generating a PDF file from HTML. However, I have encountered an issue where the table exceeds the page width. As a result, I am seeking a solution to display this table vertically. Is there a way to achieve ...

Issue with background image positioning in IE 7 while scrolling

I am struggling with creating nested divs where the middle one has a fixed background image that remains static while the rest of the content scrolls. My solution works in Firefox, Chrome, and Opera but I'm encountering issues in IE7. Despite knowing ...

Is there a way to trigger jQuery animations even when the browser window is not in focus?

Hi there, I am currently working on developing an ajax-based multiplayer game that connects to a server for updates. The game has various game states and requires the GUI to be animated accordingly. However, I have encountered a problem where jquery anima ...

Learn how to use onclick event in an anchor tag to send post values through Ajax!

Can I send post values via AJAX using an onclick event on an anchor tag? I've tried the following code but I'm not receiving any post values. How can I make it work? ............................................................................. ...

Tips for correcting the sentence that extends beyond the boundaries of the Material UI box

Utilizing Material UI for my project... I am trying to contain the text within a box but facing issues with responsiveness as the text is overflowing outside of the box. Note: I have attempted various solutions from Stack Overflow such as word-wrap, max- ...

Is there a way to keep this table fixed in place as the user scrolls?

Is there an alternative way to fix the content on the header so that it remains visible on the screen until the next table, even when scrolling? I've tried using position: sticky and top: 0, but the header still scrolls past. I have checked for any ov ...

Having trouble with the layout on my Django html page, need some help fixing it

I am encountering two challenges while designing the layout for my HTML form page. 1. In screenshot number 1, you can see that I intended to place a button next to the type field, but it appears below instead of side by side no matter what I attempt. 2. ...

Resizing the md-dialog-container in angular-material2 can be achieved by adjusting the size based on the dropdown component present in the

Currently, I am utilizing Angular Material2's dialog component. Within the dialog, I have incorporated input fields and angular2-dropdown-multiselect. The issue arises when I open the dropdown, as it automatically adds a scrollbar to the dialog box. ...

Angular component causing style disruptions

As a newcomer to Angular, I am currently in the process of converting my previous project from .net to angular. However, I have encountered an issue that is specifically related to Angular, so please forgive me if it seems trivial. I am facing difficulti ...

Flex sidebar collapse menu

I am currently in the process of developing an admin panel for my website. I have a sidebar menu that I would like to hide behind a hamburger icon and only expand when clicked on. After researching potential solutions, I haven't found much that fits m ...

Accessing data from charts that have been saved in html format using R highcharter

I utilize the highcharter package in R to visualize data and save the plots as interactive HTMLs. Often, I create multiple graphs and combine them into a canvas for better presentation. require(highcharter) hc_list <- lapply(list(sin,cos,tan,tanh),mapp ...

Modifying the CSS of highlighted text with the help of JavaScript

I am currently working on a JavaScript bookmarklet that will function as a highlighter, changing the background color of selected text on a webpage to yellow when the bookmarklet is clicked. The code I have for retrieving the selected text is functioning ...

How can HTML content be stored in a variable using JavaScript?

Today, I delved into JavaScript basics and managed to create a simple HTML page that allows users to add or remove list items. While I am aware that there are more advanced solutions out there, I believe that for my learning process, this accomplishment is ...

Issues with HTML5 video playback in Apple machines using the Firefox browser

On a website I'm developing, I've included an HTML5 video that works perfectly except for one specific issue - it won't play on Firefox in Apple devices. Surprisingly, it functions well on all other browsers and even on Firefox in Windows an ...

how do I modify my JavaScript code to achieve the desired outcome

How can I program a button to disable after being pressed 10 times in less than a minute, but continue counting if not pressed for 1 minute? function buttonClicked() { if (totalCount + accCounter > 9) { document.getElementById("btn").disabled = ...

What is the best way to transfer information between two React.js files?

I am currently finding it inefficient to pass data from App.js to another .js file within React by constantly reading and writing from local storage. I would prefer to only retrieve data from local storage once when the App.js component mounts. App.js: ...

Issue with AngularJS: Local storage not saving updated contenteditable data

My local storage implementation stops working when I attempt to incorporate contentEditable feature. Here is the link to the CodePen for reference: https://codepen.io/zanderbush/pen/WNwWbWe. Any assistance would be greatly appreciated. The functionality w ...