Tips for concealing the loader once all pages have been loaded

Within the context of my website development project at , I am utilizing a script for infinite scrolling to consolidate multiple pages into one seamless scrolling experience.

I am seeking a solution to hide the loader (the spinning icon) when no additional pages need to be loaded. I attempted to use the following code snippet to detect errors ("

Failed to load resource: the server responded with a status of 404 (Not Found)
") and trigger the hiding process, but it did not produce the desired outcome. Is there something crucial that I might be overlooking?

window.addEventListener('error', function(e) {
  $('loading').fadeOut()
}, true);

The code I have implemented to load more content is as follows:

//implementing infinite scrolling
$grid.infinitescroll({
  // Element containing pagination links
  navSelector: '.pagination',

  // Selector for the next page link
  nextSelector: '.pagination a',

  // Selector for items to retrieve
  itemSelector: '.grid-blog',
},

// Callback function executed after retrieving new elements
function(new_elts) {
  var elts = $(new_elts).css('opacity', 0);

  elts.animate({opacity: 1});
  $grid.packery('appended', elts);

  $('.target-resize').textfill({
    maxFontPixels: 36,
    changeLineHeight:false
  })

  $grid.packery({
    itemSelector: '.grid-blog',
    gutter: 20,

  })
});     

Answer №1

To address your query effectively, we need to examine the code responsible for making HTTP calls in order to load your content. However,

1) It's possible that an error occurs while there are still contents waiting to load, causing your loader to vanish even though loading is not complete.

2) You should have a mechanism in place to inform your website about what needs to be loaded. This could involve an array of URLs or similar structure that can help in concealing the loader once all content is retrieved.

3) A function dedicated to making HTTP calls to retrieve content must exist somewhere in your code. This function should include a callback where any errors encountered can trigger the hiding of the loader.

Due to the limited visibility of your example code, it's challenging to offer more detailed guidance.


edit: upon reviewing your code, you may want to try:

// Function executed after fetching elements
function(new_elements) {
    if(!new_elements) {
        $('loading').fadeOut();
        return;
    }
...
}

While this suggestion might not be optimal, ideally your plugin should feature a built-in function to halt requesting new pages. Lacking insight into the specific function handling HTTP calls or a URL array/iterator, providing assistance is challenging.

You might find this demo helpful too: https://codepen.io/desandro/pen/rwwoGe

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

Having trouble with Angular JS $scope.$apply due to an interpolation error displaying "TypeError: Converting circular structure to JSON"?

I have created a specialized angular directive shown below: dirs.directive('sectionInfo', function(){ return { restrict: 'E', templateUrl: 'partials/section-home.html', transclude: true, co ...

What strategies can be employed to streamline the code provided?

Can someone help simplify this JavaScript code for me? I would really appreciate it. Thank you! $(function() { $("#show1").click(function() { $("#showmore1").toggle(); }) $("#show2").click(function() { $("#showmore2").toggle(); ...

Data is not being successfully passed through Ajax

Having some issues with passing data through ajax. I've used this method multiple times before without any problems, but now it's not returning anything. Here is the javascript code: $('#contactformbtn').click(function(){ var full ...

Run a script tag prior to displaying the modal

Currently, I am attempting to display a bootstrap modal with dynamic content. One of the values being passed to the modal is the HTML that should appear inside it. The issue I am facing is that within the HTML content being passed, there is a script tag t ...

Refreshing the page triggers the callback function that retrieves the checkboxes selected in a Kendo treeview component

How can I retain the selected checkboxes after refreshing the page? Is there a way to achieve this using AJAX when submitting data to a database and then reloading the page? AJAX //AJAX call for button $("#primaryTextButton").kendoButton(); va ...

Ways to toggle the display of a div depending on various radio button selections

Currently, I am working on a project using HTML along with Bootstrap and Jquery. My objective is to dynamically hide a div based on the selection of multiple radio buttons without requiring a submit button. The code snippet that I have provided below works ...

The jQuery panel slider magically appears when you click the button, but refuses to disappear

One issue I am facing on my webpage involves a button that triggers a right panel to open using the jquery and modernizr frameworks. The button is positioned at the far right of the screen. When clicked, it slides to the left along with the panel it reveal ...

Choose to either push as a single object or as individual items

I have a quick question that I'd like to get some clarity on. Can someone explain the distinction between these two code snippets: export const addToCart = function(product, quantity){ cart.push({product, quantity}); console.log(`${quantity} ...

Loading JSON data into HTML elements using jQuery

I am currently grappling with coding a section where I integrate data from a JSON file into my HTML using jQuery. As a newbie to jQuery, I find myself at a standstill. https://jsfiddle.net/to53xxbd/ Here is the snippet of HTML: <ul id="list"> ...

What is the best way to incorporate an AppBar featuring a Back to Top button from Material UI for React into my application?

While exploring the Material UI documentation, I came across this interesting code snippet: import React from 'react'; import PropTypes from 'prop-types'; import AppBar from '@material-ui/core/AppBar'; import Toolbar from &ap ...

Suggestions for returning success from server side to ajax call in Ember.js

I am new to Ember and jQuery, starting out as a beginner. I'm working on creating a login page but I'm unsure about the server-side response for failed logins. My current code looks like this: App.LoginController = Ember.Controller.extend({ ...

Changing the position of the checkbox label to be above the checkbox

Can you help me with rearranging the checkbox label position to be above the checkbox instead of on the left side? I currently have the labels appearing on the left-hand side of the checkboxes, but I would like them to be positioned above the checkboxes. ...

Tips for Keeping Footer Aligned with Content:

When checking out this website, you may notice that the footer appears to be affixed to the left side. The CSS code responsible for this is as follows: #footer { width: 800px; clear:both; float:right; position:relative; left:-50%;} I would appreciate it ...

Adapting iFrame height to accommodate fluctuating content height in real time (details included)

I have an embedded iframe that contains a form with jQuery validation. When errors occur, the content height of the iframe increases dynamically. Below is the script I use to adjust the height of my iframe based on its content: function doIframe(){ o = d ...

What is the reason behind shadow dom concealing HTML elements when viewed in inspect mode?

https://i.stack.imgur.com/UZM7f.png Monday.com has implemented Shadow Dom to protect its source code. How can I work around this limitation? ...

Issue with using the character '#' in a JSON as a parameter in $AJAX URL

I have encountered an issue with the following JQuery ajax call where a JSON parameter is being truncated on the server if LoadFileSeperator = '#'. Despite this, the code works fine otherwise. What can I do to encode LoadFileSeperator in a way t ...

Implementing a Div response within the actionPerformed method

I've spent hours working on this javascript/ajax code trying to get it to add a div response that was echoed by a php script. Any assistance with this would be greatly appreciated. <form id="form1" name="form1" method="post" enctype="multipart/for ...

Ensure a field is required if the integer field is not empty in Angular Schema Form

I am currently working on setting up a form using Angular JSON Schema Form. My goal is to make one field (dropdown1) required only when another field (number1) has been filled in. I have managed to successfully get the following form + schema to function p ...

Issue with Bootstrap-vue pagination navigation not functioning correctly (unexpectedly refreshes upon clicking a page)

I recently updated my website's gallery pagination by following a helpful guide. However, I encountered a problem where clicking on a new page number refreshes the entire webpage, unlike the smooth transition shown in the tutorial. This is not the beh ...

Having trouble getting dynamic values to render properly in Ionic select? Find a solution in Ionic 4

Encountering an issue with Ionic 4 and ion-select. The problem arises when attempting to bind data, specifically when preselecting data. In this scenario, the ion-select element fails to render properly. <ion-item class="transparent"> ...