full-page graphics with dynamic transition

I have been experimenting with creating a smooth fade-in and fade-out transition between two pages that feature full-screen images. My current approach involves using the swup plugin.

To display a new full-screen image on each page, I assign a class to every HTML element, like so:

    <!DOCTYPE html>
    <html lang="en" class="home_bg">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <link rel="stylesheet" href="style.css">
        <title>Home</title>
    </head>
<body>
    <nav>
        <a href="/index.html">Home</a>
        <a href="/about.html">About</a>
    </nav>   
</body>
</html>

And for the CSS styling:

*{
    margin: 0;
    padding: 0;
}
.home_bg {
    background: url(img/landscape.jpg) no-repeat center center fixed;
    background-size: cover;
}
.about_bg {
    background: url(img/ocean.jpg) no-repeat center center fixed;
    background-size: cover;
}
nav{
    font-size: 24px;
}

Here is the HTML structure for the transition effect:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script defer src="node_modules/swup/dist/swup.min.js"></script>
    <script defer src="script.js"></script>
    <link rel="stylesheet" href="style.css">
    <title>Home</title>
</head>
<body>
    <nav>
        <a href="/index.html">Home</a>
        <a href="/about.html">About</a>
    </nav>   
    <main id="swup" class="transition-fade">
        <h1>This is home</h1>
    </main>
</body>
</html>

And the corresponding CSS styles:

*{
    margin: 0;
    padding: 0;
}
nav{
    font-size: 24px;
}

.transition-fade{
    opacity: 1;
    transition: 500ms;
}  
html.is-animating .transition-fade {
    opacity: 0;
}

To enable the transition effect, include this one-line JavaScript code:

const swup = new Swup();

However, I am currently facing a challenge in getting the full-screen images and the transition effect to work together seamlessly. It appears that the issue arises from placing the image within the 'swup' element, leading to difficulties in controlling its size and proportions even with a dedicated class.

I have tried numerous solutions and searched online for several days without success. As a beginner in HTML, CSS, and JavaScript, I am wondering if I should explore alternative approaches.

Any guidance or assistance on this matter would be greatly appreciated.

Thank you.

Answer №1

After some trial and error, I was able to come up with a solution for this issue. It might not be perfect, so if you know of a better way, please share it with us.

To fix this problem, I inserted the following HTML code just below the navigation bar:

<main id="swup" class="transition-fade">
        <div class="background-parent">
            <div class="background-home"></div>         
        </div>
</main>

Additionally, in the CSS file, I made the following adjustments:

.background-home {
  width: 100%;
  height: 100%;
  background: url(img/landscape.jpg) no-repeat center center fixed;
  background-size: cover;
}

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

Is there a shorter method to continuously run a function based on keypress in a specific scenario?

What is the goal of my task? My objective is to keep the movement of the TrumpHead going until another key is pressed to change its direction, similar to the game snake. I am considering creating multiple cases with functions containing cases within each ...

Navigating events within the Material Design Light (MDL) mdl-menu component can be

I am utilizing Material Design Light with just PHP, jQuery, and MDL min CSS and JS, no other frameworks involved. Keeping it simple with a basic menu. <button id="lang-switcher" class="mdl-button mdl-js-button mdl-button--fab mdl-js-ripple-effect"> ...

I'm struggling to understand how to interpret this. The v-tab function seems to be generating a button with various properties, but I'm unsure which specific property is related to

The V-tab below generates the button known as the right one on the v-app-bar: https://i.stack.imgur.com/DzNmq.png <v-tab :to="'/demo'" active-class="text--primary" class=&quo ...

Use ag-Grid to customize your column headers with checkboxes, allowing you to easily select or deselect all items in that column. This feature is not limited to

In my experience with ag-grid, I often find myself needing to customize the first column header to include a checkbox. This allows me to easily perform actions such as selecting all or deselecting all rows in the grid. It's important to note that this ...

How does Code Sandbox, an online in-browser code editor, manage file storage within the browser?

What are the ways in which Code Sandbox and StackBlitz, as online in-browser code editors, store files within the browser? ...

Angular: promptly exit out of ngClick event handler

I have a selection menu on my webpage that is essentially an unordered list, with each item in the menu formatted like this: <li ng-click='doCalc(5)'>Five</li> The doCalc function that is triggered by clicking on these items may tak ...

Utilize Python and BeautifulSoup for parsing HTML with multiple tags and classes

I am currently attempting to navigate through a complex HTML structure. Here is the snippet of the HTML code: <div class="example one"> <ol class="example two"> <li class="example three"> My object ...

Utilizing Observables in NestJS: Exploring SSE and EventEmitter

I am working on a project where I need to display an event that occurs in the backend on the frontend. Since it is a one-way communication, I have decided to use SSE (Server Sent Events) in nestjs to push the event to the frontend. The setup, as per the do ...

Adjust the ribbon's width without altering its placement in order to make it fit snugly inside the box

Is there a way to decrease the width of the ribbon while keeping its position intact? I need some guidance on what I might be doing wrong. .ribbon-content { position: relative; } .ribbon-content>[class*=ribbon] { position: absolute; z-index: ...

Utilizing Hyperlinks in jQuery DataTables Cell with Data Pulled from Mysql Table

I have a question that builds upon the one before it: How to display a hyperlink in a cell with jQuery DataTables There is also a Fiddle link provided My current query revolves around implementing hyperlinks when fetching data from a MySQL database table ...

Changing color of Font Awesome Icons upon hover, without any animation

I need assistance with changing the color of font awesome icons on hover without any animation. Specifically, I want the icon colors to transition from indigo to blue and finally red when a user hovers over them, without the colored icon appearing abruptly ...

Deciding the source URLs for external iframes

Is it possible to detect the URL displayed in an iframe? How can we ensure that links within an iframe open in a new tab/window? Moreover, is there a way to achieve this even with the same-origin policy for external frames? If not, what causes this violat ...

Enhance the readability of your Angular/Ionic applications with proper hyphenation

In my Ionic 3 app, I am using an ion-grid. Some words do not fit within the columns and are cut off, continuing on the next row without any hyphens added for proper grammar context. See image https://i.stack.imgur.com/3Q9FX.png. This layout appears quite ...

How to vertically align a div or input element with Bootstrap

https://i.sstatic.net/2OHp2.png This is the code I'm currently using: <body class="bg-light"> <div class="row justify-content-center mt-3"> <div class="col-6"> <in ...

Having trouble with Vue.js 2.5+ and Webpack 4+ not loading CSS files?

I am currently in the process of setting up a Vue project with webpack 4 enabled using the Microsoft SPA templates dotnet core as the base. Everything seems to be working fine, except for the fact that external CSS files are not loading into the project. I ...

Is it feasible to use PHP code within a Javascript environment?

Looking for help with integrating PHP code into a JavaScript script: var bigData = { "teams" : [], "results" : [] }; for( var i=1 ; i<16 ; i+=2 ) { bigData.teams.push(["<?php echo 1; ?>",'Team '+(i+1)]); } for( var j=1 ; j& ...

Position the button at the bottom of the page with MUI v5 in a React application

How can I ensure the button is always positioned at the center bottom of the page, regardless of the content height? This is a snippet from my code: const useStyles = makeStyles({ button: { bottom: 0, right: 0, position: "absolute" ...

Align an Image Vertically Using Bootstrap's Grid System

Hey there! I've been trying to center an image within a "div" tag using Bootstrap, but despite my best efforts and reading through various resources, I haven't been able to crack it. * { margin: 0; padding: 0; } .people-one { w ...

Having Trouble with JQuery Triggering Tabs inside an iFrame

I am curious why this code functions properly on my parent's HTML page: $("#assessmentsTab").trigger("click"); but fails to work within my iFrame: $("#assessmentsTab", window.parent.document).trigger("click"); Does anyone have any suggestions? I ...

Integration of Angular.js functionalities within a Node.js application

After working on my node.js app for a few weeks, I decided to add some additional features like infinite-scroll. To implement this, I needed to use packages in node.js along with angular.js. So, I decided to introduce angular.js support to the app, specifi ...