Tips for integrating a logo into router view animations

How can I incorporate a logo into the white fade-in screen that appears when navigating between subpages using <router-view> within App.vue?

Here is a simplified version of my App.vue code:

<template>
    <div id="app">
        <div class="site-content">
            <header></header>
            <transition name="fade" mode="out-in">
                <router-view/>
            </transition>
            <footer></footer>
        </div>
    </div>
</template>

<script>
    /*---*/
</script>

<style>    
    /*---transition---*/
    .fade-enter-active,
    .fade-leave-active {
        transition-duration: 0.3s;
        transition-property: opacity;
        transition-timing-function: ease;  
    }

    .fade-enter,
    .fade-leave-active {
        opacity: 0;
    }    
</style>

Answer №1

To achieve this effect, one method is to assign each "page" a style of position: relative, and then add a layer behind the pages containing your logo:

var firstPage = {
    template: `
        <div class="page">
            <router-link :to="{name:'page2'}">page 2</router-link>
        </div>
    `,
}
var secondPage = {
    template: `
        <div class="page">
            <router-link :to="{name:'page1'}">page 1</router-link>
        </div>
    `,
}

var routes = [
  { name: 'page1', path: '/', component: firstPage },
  { name: 'page2', path: '/first', component: secondPage }
]

const router = new VueRouter({
  routes // short for `routes: routes`
})

var app = new Vue({
    el: '#app',
    template: "#template",
    router,
})
.app, html, body {
    min-width: 100%;
    min-height: 100%;
    height: 100%;
}


/*---transition---*/
.fade-enter-active,
.fade-leave-active {
    transition-duration: 0.3s;
    transition-property: opacity;
    transition-timing-function: ease;  
}

.fade-enter,
.fade-leave-active {
    opacity: 0;
}    



.page {
    position: relative;
    background: white;
    min-width: 100%;
    min-height: 100%;
}
.logo {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
 }
 
 
 
<!-- development version, includes helpful console warnings -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

<!-- router -->
<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>

<div id="app"></div>

<template id="template">
    <div class="app">
        <div class="logo">
            TEST LOGO
        </div>
        <transition name="fade" mode="out-in">
            <router-view/>
        </transition>
    </div>
</template>

Although it may appear daunting with all this code, most of it is actually boilerplate necessary to set up vue-router in order to demonstrate the example.

In normal operation, the page is completely on top, obscuring the logo underneath. However, when you switch between pages, the current page fades out, making the logo more visible since it's positioned beneath, before fading out again as the new page loads.

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

Error encountered during navigation: navigator has not been defined

I encountered an issue where the page gets redirected upon form submission without triggering the catch block. However, in the backend, I am facing an error stating that the API body is not being executed. Below is the code snippet of the page: "use cl ...

Is it possible to pass the index variable of a for loop to a different function?

As a current bootcamp student, I have a question about passing the index of a for loop to another function. Specifically, I am trying to fetch data from an API (which provides me with a random cryptocurrency from an array) 4 times and then pass that data ...

Is it safe to incorporate bootstrap.js into a bootstrap-vue project?

I am currently working on a VueJS application that functions like a calculator. This app will be attached to a DOM element within an established "static" webpage on a CMS platform with Bootstrap 4 themes. The navigation bar and other site features rely on ...

Steps to update the active state in the "reducer" when clicking on elements outside of the "reducer" area

Working with react-redux has presented some challenges for me. I've created multiple reducers such as action, root reducer, active_step reducer, and list_step reducer. One aspect that I find intriguing is the ability to dynamically map and change the ...

Retrieve the native interface from the Puppeteer browser/page context

Can a native interface be obtained from the Browser or Page instance to verify if an object is an instanceof this interface? For example, in a testing scenario with jest (where CanvasRenderingContext2D is not available due to being a Node context rather t ...

From creating a simple jQuery fiddle, let's delve into the world

Here is a code snippet I'm trying to transition from jQuery to an Angular directive. Visit this link to view the original code: http://jsfiddle.net/rhtr1w04/ Below is my implementation in app.js: angular.module('app',[]).directive('an ...

Having trouble with Vee-validate Basic example - undefined errors issue

I've been struggling to get a basic form validation page working with vee-validate. Something seems to be going wrong, but I can't pinpoint the exact issue. Why am I seeing the error: errors not defined. <!DOCTYPE html> <html> < ...

The HTML select element fails to drop down over the THREE.js scene

I'm currently working on enhancing the Three.js editor for a project. editor link One of the tasks I'm tackling is adding a select element on top of the viewport in the editor. Unfortunately, the dropdown functionality of the select element isn ...

Unable to locate index.html file in Docker container while dockerizing React application

I'm a newcomer to Docker and I'm looking to containerize my react app. The index.html file is located in the public folder within my react project. However, when I try to run the docker image, it fails with an error indicating that the index.html ...

CryptoJS consistently produces identical hash values for distinct files

Utilizing CryptoJS to generate a hash value for uploaded files has presented me with a challenge. Despite my efforts, all files I upload seem to produce identical hash values. It appears that the issue lies within my "onFileChange" function, but pinpointin ...

Determine the number of properties present in two arrays by comparing them

Looking to compare two arrays and determine the count of items in the master list. A sample master list could be: { name: 'Emily', age: 29 }, { name: 'Jack', age: 31 }, { name: 'Lily', age: 28 }, { name: 'Emily', a ...

Retrieving the selected option from a dropdown list in VueJS

I have been struggling to store the selected value from a dropdown list as a data object in Vue. Despite my attempts, I am unable to successfully save the value in the Vue data object. I have experimented with using onchange and v-model.lazy, but I am unsu ...

Encountering an error while trying to add text: SyntaxError - Unexpected token 'for

I'm trying to print out the elements of an array using JavaScript. let listToArray = ["a","b","c"]; $(".tooltip").append(for(let i = 0; i < listToArray.length; i++) {listToArray[i]}); But I keep getting an error that says Uncaught SyntaxError: U ...

Troubleshooting async/await issues in certain IDEs

I've been experimenting with aysnc and await in my project. While it worked perfectly in FiddleJS, I encountered an error when trying to implement it in my IDE (PHPSTORM 2017): async function test(url){ ^^^^^^^^ SyntaxError: Unexpected token f ...

The onClick event handler is triggered on page load instead of waiting for a click

Recently delving into React, I encountered an issue while attempting to call a function set as a prop. Take a look at my component below: class SamplesInnerLrg extends Component { playSampleAction(sample,sampleId) { console.log(sample); } ...

What is the significance of using angular.forEach in this context?

While examining the functionality of the angular.forEach function: Below is the code snippet for angular.forEach: var values = {name: 'misko', gender: 'male'}; var log = []; angular.forEach(values, function(value, key) { this.push( ...

When utilizing JavaScript within an Electron application file that is linked with a script tag in an HTML document, there may be limitations on using node modules with

While working on my Electron application, I encountered an issue with referencing a node module using require within an HTML form that includes JavaScript. Specifically, I am having trouble integrating the 'knex' node module into my code. Here i ...

Executing a function in Vue.js upon state changes

I am trying to trigger a function when the state changes in my Vue app. In my component, I can retrieve the boolean state of isOpen. The goal is to execute a function that sets focus on my form input when the modal opens and isOpen is true. I attempted ...

Trouble arises when attempting to incorporate the Restangular dependency with Angular using browserify

I've been using browserify to manage my angular dependencies successfully, however, when I try to add restangular I encounter an error: "Uncaught Error [$injector:modulerr]". Here's a glimpse of my package.json: "browser": { "angular": "./ ...

Controlling JavaScript Text Opacity on Scroll: Smooth Transitions from Invisible to Visible to Hidden

I am attempting to replicate the Apple Airpods page, including its animation. I have successfully implemented the animation and now I am working on rendering text while scrolling. The text appears correctly but I'm facing an issue with opacity transit ...