Tips for displaying website preloader just once

I recently added a preloader to my website, but I'm having trouble getting it to only play once per visit. Ideally, I want the animation to show up when the site is opened in a new tab or browser window, but not when navigating through the domain by clicking on the home button or using the back button. I attempted to use cookies to achieve this, but for some reason, it's not working as intended.

Here are some details about the preloader: It is created using CSS @keyframes and it is not a .gif file.

If you need a reference, my website's domain is jonrouse.com.

HTML

<div class="preloader">
   <div class="loader">
        <div class="loader-inner"></div>
   </div>
</div>

CSS

.preloader {
    display:block;
    position:fixed;
    top:0;
    left:0;
    right:0;
    bottom:0;
    z-index:99;
    margin:0 auto;
}

JS

<script type="text/javascript">
    $(document).ready(function() {
        $(window).load(function() {
            function Preloader() {
                var preloader = $ ('.loader');
                preloader.delay(1000) .fadeOut (500);
                var preloader = $('.preloader');
                preloader.delay (1500) .slideUp(500);
            }
            Preloader();
        });
    });
</script>

I would really appreciate any help with resolving this issue. Feel free to ask if you need any additional information.

Answer №1

Here is an example of utilizing sessionStorage to display a preloader only once during each visit in a tab or window.

<script type="text/javascript">
$(document).ready(function() {
    $(window).load(function() {
        function DisplayPreloader() {
            var preloader = $ ('.loader');
            preloader.delay(1000) .fadeOut (500);
            var preloader = $('.preloader');
            preloader.delay (1500) .slideUp(500);
        }
        if ( ! sessionStorage.getItem( 'doNotShow' ) ) {
            sessionStorage.setItem( 'doNotShow', 'true' );
            DisplayPreloader();
        } else {
           $ ('.loader, .preloader').hide();
        }
    });
});
</script>

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

Bootstrap Scrollable Card

Currently, I am working with bootstrap 4 and have set up a layout with 3 columns in a single row. One of the columns contains a list while the other two do not. I am trying to make only the column with the list scrollable without affecting the entire conta ...

I am searching for answers to solve issues related to a JSON file

I am currently working on a tool that searches for matches in an input field by comparing the keywords entered by the user with a JSON. During my testing phase, I focused on using a single API that provides information about different countries and fortun ...

Methods of using jQuery to conceal table rows according to child class name

I need to filter out rows in a table that do not contain a specific class. For instance: <tr id="game-22590" class="game"> <td class="pos left-edge"> <div>2</div> </td> <td class="cost"> < ...

Seeking assistance in developing a dynamic footer complete with a gallery of images

Attempting to create a footer packed with images but struggling to ensure it looks good on both PCs and mobile devices. The goal is to align the bronze sponsor kitten to the left, and supporter kittens to the right, while keeping the footer at a reasonabl ...

Is there a way to verify that all of my HTML elements have been loaded in AngularJS?

I am currently utilizing angularJS version 1.2.1 along with angular-ui-bootstrap. Within my code, I have a collection of <ng-includes> tags from angularjs and <accordion> components from angular-ui. When loading the content, I need to initiat ...

Uploading files in AngularJS using Rails Paperclip

I have been working on implementing a file upload feature with AngularJS/Rails using the Paperclip gem. I was able to resolve the file input issue with a directive, but now I am facing an issue where the image data is not being sent along with other post d ...

Is there a way to effectively overwrite CSS styles when utilizing @extend with another class in SCSS?

Here is some SCSS code I am working with: .a { height: 100px; width: 100px; } .b { @extend .a; height: 200px; } After compiling, the CSS appears as follows: .a, .b { height: 100px; width: 100px; } .b { height: 200px; } Whe ...

Setting !important to every property's value at once

One interesting approach I am using is applying !important to all of the css properties' values like this: .someclass{ color: #f00 !important; background-color: #ff0 !important; margin: 0 !important; padding: 0 !important; width: 100% ! ...

How can you utilize the Array submission syntax within HTML coding?

I currently have numerous input fields within a form, and some of them are structured like this: <input name="agents[]" type="file" /> Additionally, imagine there is a plus button next to this field as shown below: <img src="plus.jpg" id="some_ ...

A helpful guide on presenting chart data in HTML table format using Chart.js

Is there a way to convert chart data into an HTML table upon button click using Chart.js? I have successfully created a line chart with Chart.js, with the x-axis representing colors and the y-axis representing votes and points. Here is a link to a workin ...

Styling Your Navigation Bar with CSS and Active States

Creating an interactive navigation element for a menu can be challenging, but here's a helpful example. http://jsfiddle.net/6nEB6/38/ <ul> <li><a href="" title="Home">Home</a></li> <li class="activ ...

Fade the inner content of a div using jQuery

Hi there, I've managed to toggle my footer up and down using this code. However, I would like the current content of the footer to fade out while new content fades in when it's toggled down. Unfortunately, I can't seem to figure it out on my ...

Securing Node function parameters in an asynchronous environment

I've been grappling with a pressing question lately, and I just can't seem to find a definitive answer. Let me share with you a Node function that I frequently use. It manages web requests and conducts some input/output operations: function han ...

What could be causing the issue with this function not loading correctly the first time in Node.JS?

I am currently in the process of developing a Twitter bot using Node.JS. One issue I am facing is with a function that utilizes an npm library called "scrapejs" to extract data from Yahoo Finance. The problem arises when this function loads after the initi ...

Creating a Social Media Platform with JavaScript, Bootstrap, JQuery, PHP, and Mysqil

I am currently in the process of developing a social networking platform that will have similar features as Instagram. Users will be able to log in, create posts, leave comments, like content, share posts, and send data to a server for storage or display p ...

Definition of a jQuery plugin

There's an aspect of the traditional jQuery plugin definition that remains elusive to me, and it seems that no tutorial on plugins addresses this issue. Many plugin definitions I've come across follow a pattern similar to this: (function($) { ...

The duplication of printed keys and values from a JavaScript object is causing issues

I am working with a JSON object structured like this: var data = { "2020-01-20": ["08:00 - 09:00", "09:00 - 10:00"], "2020-01-21": ["08:00 - 09:00"] }; My objective is to display each value along with its corresponding key in a list format, as follow ...

Issue with fulfilling Ajax promises

How can I properly use a promise to compare the current logged-in user with a field from a list in SharePoint? function compareCurrentUserWithListObject() { var userProp = this._userProfileProperties; var userName = userProp.get_userProfilePropertie ...

Tips for managing submitted data to a server in express?

In the process of sending a post request from my index.js to app.js upon a click event, I have the following code snippet: var data = { name: "Sarah", age: "21" }; var xhr = new XMLHttpRequest(); xhr.open("POST", "/", true); xhr.setRequestHe ...

A step-by-step guide on storing JSON data into a variable using NodeJS

Just starting out with Node.js and running into an issue. I need to figure out how to extract and save data from a JSON object retrieved from the GitHub API. var http = require("http"); var express = require('express'); var app = express(); var ...