Slideshow featuring a dynamic ken burns effect with color overlays

I am having an issue with my ken burns effect slideshow on the mobile site. I am trying to add an overlay that automatically switches between green, red, yellow, and blue colors but it's not showing up. I can't seem to figure out what the problem is. Any assistance would be greatly appreciated.

HTML:

 <div id="slideshow">
     <img src="images/Campus2.jpg" alt="school pic">
     <img src="images/bio_lab_optimised.jpg" alt="bio lab pic">
     <img src="images/Capture.jpg" alt="school pic">
     <img src="images/class_optimised.jpg" alt="class pic">
     <img src="images/LFPS_optimised.jpg" alt="school pic">
     <img src="images/phy_lab_optimmised.jpg" alt="physics lab">
     <img src="images/cs_lab.jpg" alt="class pic">
     <img src="images/x-optimised.jpg" alt="school pic">
     <img src="images/page-1-hero-image.jpg" alt="school's image">
     <img src="images/kindergarten2.jpg" alt="kindergarten">


</div>

CSS: (for overlay)

.overlay {
    position: relative;
    top:0;
    left:0;
    width:100%;
    height:100%;
    display: block;
    z-index:3;
    animation: color-animation 80s linear alternate;
}

@keyframes color-animation {
    0% {
        background-color: rgba(255,0,0,0.5);
    }

    25% {
        background-color: rgba(0,255,0,0.5);
    }

    50% {
        background-color: rgba(0,0,255,0.5);
    }

    100% {
        background-color: rgba(255,255,0,0.5);
    }
}

CSS: (ken burns effect)

#slideshow{
    position: relative;
    overflow: hidden;
    width: 100vw;
    height: 100vh;
}

#slideshow img {
    position: absolute;
    left: 0;
    top: 0;
    z-index: 1;
    /* to make pic responsive */
    min-height: 100%;
    min-width: 1024px;
    width: 100vw;
    height: 100vh;
    opacity:0;
    -webkit-transition-property: opacity, -webkit-transform;
    -webkit-transition-duration: 3s, 45s;
    -moz-transition-property: opacity, -moz-transform;
    -moz-transition-duration: 3s, 45s;
    -ms-transition-property: opacity, -ms-transform;
    -ms-transition-duration: 3s, 45s;
    -o-transition-property: opacity, -o-transform;
    -o-transition-duration: 3s, 4s;
    transition-property: opacity, transform;
    transition-duration:3s, 45s;
}

#slideshow img {
    -webkit-transform-origin: bottom left;
    -moz-transform-origin: bottom left;
    -ms-transform-origin: bottom left;
    -o-transform-origin: bottom left;
    transform-origin: bottom left;
}

#slideshow img:nth-child(2n+1) {
    -webkit-transform-origin: top right;
    -moz-transform-origin: top right;
    -ms-transform-origin: top right;
    -o-transform-origin: top right;
    transform-origin: top right;
}

#slideshow img:nth-child(3n+1) {
    -webkit-transform-origin: top left;
    -moz-transform-origin: top left;
    -ms-transform-origin: top left;
    -o-transform-origin: top left;
    transform-origin: top left;
}
#slideshow img:nth-child(4n+1) {
    -webkit-transform-origin: bottom right;
    -moz-transform-origin: bottom right;
    -ms-transform-origin: bottom right;
    -o-transform-origin: bottom right;
    transform-origin: bottom right;
}

/**
 * Because of the stacking context, we need to make sure that the first image (in source) is not hidden by the last one.
 * The rule below moves all images past the second one down the stack.
 * This is because the second image needs to show on top of the first one when it transitions in.
 */

#slideshow .fx:first-child + img ~ img  {
    z-index:-1;
}

/**
 * Because images are styled with a different point of origin, the following rule will create different panning effects.
 */

#slideshow .fx {
    opacity:1;
    -webkit-transform: scale(1.5);
    -moz-transform: scale(1.5);
    -ms-transform: scale(1.5);
    -o-transform: scale(1.5);
    transform: scale(1.5);
}

Javascript:

 function slideEffect(){
            //apply fx class to first element
            document.getElementById('slideshow').getElementsByTagName('img')[0].className = "fx";
            //loop kenburns effect every 15 seconds
            window.setInterval(kenBurns, 15000);
            //gets all images under slideshow
            var images = document.getElementById('slideshow').getElementsByTagName('img'),
                    numberOfImages  = images.length,
                    i= 1;

            function kenBurns() {
                //applies class fx appropriately
                if(i==numberOfImages){ i = 0;}
                images[i].className = "fx";
                if(i===0){ images[numberOfImages-2].className = "";}
                if(i===1){ images[numberOfImages-1].className = "";}
                if(i>1){ images[i-2].className = "";}
                i++;
            }
        };

if (window.innerWidth < 480)
{
     $('#slideshow').addClass('.overlay');
}
slideEffect();

Answer №1

Modifying the appearance of #slideshow is what you are essentially doing.

For a more efficient approach, consider adding a separate overlay above the slider. One way to achieve this is by using a pseudo-element.

I suggest utilizing media queries instead of relying on JavaScript for a cleaner solution.

To maintain your current method, update .overlay as follows:

.overlay:before {
    display: block;
    content: '';
    position: relative;
    top:0;
    left:0;
    width:100%;
    height:100%;
    z-index:3;
    animation: color-animation 80s linear alternate;
}

..or if you prefer media queries, eliminate this section:

if (window.innerWidth < 480)
{
     $('#slideshow').addClass('.overlay');
}

..and incorporate the following into the CSS code:

@media screen and (max-width : 480px) {
    #slideshow:before {
        display: block;
        content: '';
        position: relative;
        top:0;
        left:0;
        width:100%;
        height:100%;
        z-index:3;
        animation: color-animation 80s linear alternate;
    }
}

This adjustment accomplishes a similar outcome. When the screen's width falls below 480px, a pseudo-element is inserted into #slideshow, effectively serving as the overlay.

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

Check the box to track the current status of each individual row

Recently, I encountered an issue with a form containing dynamic rows. Upon fetching records, my goal was to update the status of selected rows using checkboxes. Although I managed to retrieve checkbox values and dynamic row IDs successfully in the console ...

What's preventing me from invoking this object's function through an inline anchor?

CSS: <div class="box"> <p>This is a box</p> </div> Javascript: var box = { content : (function() {return ("This is the content of the box")}) }; alert("Box content: \n" + box.content()); $("output").text( +"<br/ ...

Ways to abbreviate a URL using Next JS

While working on my Next.js application, I encountered an issue with passing an object between pages. To achieve this, I compressed my array of objects into JSON using JSON.stringify(result) on the index page and then parsed it on the second page using JSO ...

Tips on embedding a textField into a designated row within a table by clicking a button with the help of reactjs and material ui

I need assistance adding multiple text fields to a specific row within a table when a designated row's "add" button is clicked. Currently, I am able to add a text field when the button is clicked, but it adds the text field to every row in the table. ...

Experiencing difficulties retrieving a response from an API call within the Express.js backend

My backend server built with express.js is having issues making an API call. When I attempt to visit http://localhost:3004/api/weather?city=[cityName], the expected json response from openweathermap.org is not received. Instead, my middleware displays a me ...

Using Jquery Ajax with jsonp for dynamic data retrieval

Hey everyone, here's the code snippet I'm working with: $.ajax({ 'url': 'myUrl', 'dataType': 'jsonp', crossDomain: true, 'data': { // sample data }, 'success&ap ...

What is the most effective approach to handling dependencies for an AngularJs 1.x web application?

Right now, I have a bunch of script elements pointing to cdn/local files, which isn't ideal. I'm considering declaring all necessary packages using npm/yarn and serving cdn files with self-hosted fallback. Is this a good idea? Would it be bette ...

What is the best method for creating thumbnail URLs for video files in HTML with JavaScript?

I am facing an issue with generating a thumburl for uploaded video files. After dynamically creating an input file and uploading local video files, I am able to retrieve the name and size of the file along with other information as shown in the screenshot ...

Error encountered while rendering HTML template with Django and AngularJS due to TemplateSyntaxError

Hello, I am new to Angular and Django. I have built a Django webpage and am attempting to display values from a basic AngularJS app and controller tutorial using my HTML template. However, I keep encountering an error in the index.html file when trying to ...

Maintaining the format of forms input in Rails and HTML: Tips and tricks

Hey there! I'm working on a Rails app that has a simple HTML form. One of the fields is called description, which is a text_area. I want to be able to display its input exactly as it was entered on the index page. For instance: If someone enters a l ...

Using TypeScript with React and Redux to create actions that return promises

Within my React application, I prefer to abstract the Redux implementation from the View logic by encapsulating it in its own package, which I refer to as the SDK package. From this SDK package, I export a set of React Hooks so that any client can easily u ...

Jasmine and Karma: Unidentifiable variable runs

Is a special plugin or library required to use runs() and waits() with Jasmine? I checked the Jasmine wiki page for async tests at https://github.com/pivotal/jasmine/wiki/Asynchronous-specs, but there's no mention of needing additional libraries. Bas ...

Responsive Design of Iframe Not Adjusting Properly

My website features an embedded Google map in an iframe: <iframe src="https://www.google.com/maps/d/u/0/embed?mid=EXAMPLE" style="top:0px; position:fixed; float:left; width:35%; height:400px;"></iframe> Adjacent to the map, ...

What is the best way to utilize a single npm module in multiple TypeScript files?

Question: I keep encountering the error message "error TS2451: Cannot redeclare block-scoped variable 'os'" when I try to import the same npm module in multiple TypeScript files and run the TypeScript compiler tsc. Here is an overview of my proj ...

Using a combination of jQuery and AJAX to send data via a form

I've been working on a script to create a popup form that, once submitted, should trigger another function to send the data via ajax. However, I'm facing an issue where the second function isn't being activated. Can someone spot what's ...

Wrap the json response in HTML elements

I'm currently learning about AJAX, and I've encountered a major issue that I can't seem to resolve. I pass several variables to PHP, perform various checks there, and then return string values to AJAX. Strangely, I am able to display these r ...

When combining Socket.io 1.0 with express 4.2, the outcome is a lack of socket connection

According to the title, I am attempting to integrate socket.io 1.0.4 with express 4.2, but all requests with "/?EIO" are resulting in a 404 error. Below are my file configurations: ./bin/www : #!/usr/bin/env node var debug = require('debug')(& ...

Tips on how to modify the Firestore field named `likes` by incrementing or decrementing one

I have encountered an issue while trying to update a number field in Cloud Firestore. Despite following the official document and writing the code, it did not produce the desired outcome. It appears that there might be an issue with how I applied async a ...

Ways to retrieve information from a JSON entity

When dealing with both a normal array and a multidimensional array in PHP, how can I access them in jQuery after returning them using json_encode? $data['normalArray'] = $array; $data['multiArray'] = $multiArray; echo json_encode($dat ...

Connect the endpoint to a duplicate element using jsPlumb

Currently, I am working on a drag and drop application where I am integrating connecting points using jsPlumb. The application features a toolbar of components that users can drag and drop onto the canvas. When a user drops an item, I create a clone and a ...