HTML animation effect on subpage with a URL modification [LATEST UPDATE]

Can you smoothly load a new subpage in the background, update the URL, and fade it in while an animation is playing on the previous page?

Check out this example (jsFiddle) to see a simple animation:

$(document).ready(function() {
    'use strict';
    $('.r').on('click', function() {
        var preWidth = $('.l').width(),
            menuWidth = $('.r').width();
        $('.l').animate({
            left: '-' + preWidth
        }, 2000, 'easeOutQuad');
        $('.r').animate({
            left: menuWidth
        }, 2000, 'easeOutQuad', function() {
            $('.page').css({
                visibility: 'hidden'
            });
        });
    });
});

Imagine it like a sliding door. Here's how it should function:

  1. Click on the right div.
  2. The two divs slide outward.
  3. In the background, the new page fades in as the sliding animation plays.
  4. The new page becomes fully visible and the URL changes accordingly.

I hope that explanation makes sense. I appreciate any help! Have a wonderful day.

UPDATE:

Initially, I encountered an issue with my browser's back button not working correctly when trying to load the first page "loader.html" with the animation. As a workaround, I utilized an if statement to monitor a variable's state. Is there a more efficient way to handle this situation?

window.addEventListener('popstate', function(f){
        var bprsd = f.state;
        if(bprsd == null){
            bprsd = "loader.html";
        }
        if(bprsd = "loader.html" || " "){
            bprsd = null;
            location.reload();
        }
    });

You can explore the test site here

Answer №1

A response that is a mix of both affirmative and negative.

Indeed, it is achievable but not within your current framework. To accomplish this, you must load the alternate page using $.load:

var website="example.html";
$(document).on("click",function(){
  //perform fadeout
  $(document.body).load(website);
   history.pushState({},"MySite",website);
  //complete the process with fadein
  });

site="newexample.html";

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

Why is the defaultDate property not functioning properly in Material-UI's <DatePicker/> component with ReactJS?

I recently implemented the <DatePicker/> component from Material-UI ( http://www.material-ui.com/#/components/date-picker ) in my project. I encountered an issue while trying to set the defaultDate property to the current date on my computer, as it r ...

Sending JSON data from a Django view to a JavaScript function

I am trying to pass JSON data to JavaScript. I need the JSON structure to be like this: data: [ { value: 335, name: 'Coding' }, { value: 310, name: 'Database ...

What could be the reason for the ReferenceError that is being thrown in this code, indicating that '

let number = 1; console.log(number); Feel free to execute this basic code snippet. You may encounter an issue: ReferenceError: test is not defined, even though the variable was declared. What could be causing this unexpected behavior? ...

How to use jQuery to hide list items after a certain threshold

$('li[data-number=4]').after().hide(); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul> <li data-number="0"">1</li> <li data-number="1">2</li> ...

Issue with retrieving values using submit button in Jquery

JQUERY snippet $('#cartSubmit').click(function() { var productName = encodeURIComponent($('#product_name').val()); var barcode = encodeURIComponent($('#barcode').val()); var quantity = encodeURICom ...

Unusual outcome observed when inputting a random number into HTML using JavaScript

In my HTML file, I am trying to input a number within 50% of a target level into the "Attribute" field. Here is the code: <!DOCTYPE html> <html> <body> <input type = "number" name = "playerLevel" onchan ...

Positioning Google Chart in HTML

I'm attempting to arrange three distinct Google pie charts in a horizontal layout. At present, I have applied inline CSS for formatting purposes. Oddly enough, the third chart always ends up on a separate line. Could anyone kindly point out my error? ...

Issues with iFrame Alignment

I recently created a digital catalog using FlipHTML5 and realized it needed to be more mobile-friendly. To address this issue, I included the following CSS: .size { width: 85vw; height: 75vh; Although this adjustment made the catalog display correctly on ...

Escape sequences do not seem to be functioning properly when using innerHTML

I am facing an issue where a string containing HTML escape characters (such as < and >) needs to be rendered inside a div using innerHTML. The intention is for the escaped characters to appear as text rather than as actual HTML, but they still render ...

What is the point of the horizontal scroll bar in WP Thesis?

There seems to be a horizontal scroll bar appearing at the bottom of my site, even though there is no content extending beyond the visible area. Can anyone provide guidance on how to fix this issue? My website is built on Wordpress 3.0 and utilizes the Th ...

Sending an array or list of files from AJAX to the Controller

I have a task to upload multiple files and pass them to my Controller's Action. The current code is functional, but I feel there could be room for improvement as it's somewhat manual. I need to display file upload elements based on the number of ...

Using Jquery for conditional statements: if versus else

$("#bottomWatch").click(function(){ var doops = $(".videoMove").display; if (doops == "none") { $("#video").css("left","15%", "display: block"); } else { $(".videoMove").cs ...

Steps for positioning an element to the left and center of a div

I'm having trouble aligning my two elements in a simple horizontal menu to the middle left. I want them to have a margin of 5px on the left and right sides. Here is a screenshot and CSS style: https://i.stack.imgur.com/vzO5D.png .body_clr { wid ...

Utilizing the CSS grid framework to efficiently create repetitive rows and columns in code

When I work with CSS frameworks like Bootstrap or Materialize, I often find myself repeatedly typing the same HTML code: <div class="row"> <div class="col s12"> <!-- Some text/ a button / something --> </div> </d ...

Verify the middleware is connected to the express endpoint during the unit test

How can I verify that the middleware is properly attached to the route in my unit test below? The server .. var express = require('express'); var http = require('http'); var app = express(); var server = http.createServer(app); var P ...

Div element failing to respond to hover effect

I have implemented a hover effect to display an icon overlay and filter on the Instagram feed of a website I am currently working on. Everything looks perfect when I inspect the element and set the state to hover. However, when I test the website and hover ...

Confused between Javascript and PHP? Here's what you should consider!

Looking for a solution to transfer a string from JavaScript, obtained from the content of a div, to PHP in order to create a text file with this information. What would be the most effective approach to accomplish this task? Edit[1]: Using the Post ...

Utilizing ng-model to control the visibility of a label or anchor tag

Here is the code snippet I am working with: <div class="tabs DeliveryRightDiv"> <label class="selected"><a>One</a></label> <label> <a>Two</a> </label> <label> ...

Positioning JQuery tooltips

I've been developing a simple tooltip tool (check out the fiddle link below), but I'm encountering some issues with positioning. My goal is to have the tooltip appear centered and above the clicked link, however right now it appears at the top le ...

Unable to see Primereact styles reflected on components

After some investigation, I've pinpointed the issue to be related to preflight from tailwind. Upon reviewing the documentation, I came across this helpful information: CSS Layer It seems that using Tailwind CSS with styled or unstyled modes of PrimeR ...