Spinner loading animation not showing correctly

Even though it shows up when I hover over and inspect, the image remains completely invisible. It's saved in the same folder and I believe all the file names are correct, but for some reason, it's just not working as expected. Any help would be greatly appreciated since this is only for a basic note file.

JS:

const renderLoader = parent => {
    const loader =  `
        <div class="loader">
            <svg>
                <use href="32. spinner.png"></use>
            </svg>
        </div>
        `
    document.querySelector(parent).insertAdjacentHTML('afterbegin', loader);
}

HTML

<!DOCTYPE html>
<link rel="stylesheet" type="text/css" href="32. loading spinner.css">
<script src="32. loading spinner.js"></script> 

<html lang="en">
    <head>
        <meta charset="UTF-8>
        <title>Loading spinner Notes</title>
    </head>

    <body>
        <div class="results">
            <h1>RESULTS DIV</h1>
        </div>
        <div class="answers">
            <h1>ANSWERS DIV</h1>
        </div>
        <!-- EVERYTHING IS WORKING BUT THE SPINNER IS NOT SHOWING THE IMAGE -->
        <input value="load spinner for results" type="submit" onClick="renderLoader('.results')">
        <input value="load spinner for answers" type="submit" onClick="renderLoader('.answers')">

        <h1>Look at console</h1>
    </body>

</html>

CSS

.loader {
    margin: 5rem auto;
    text-align: center; }
    .loader svg {
      height: 5.5rem;
      width: 5.5rem;
      /* fill: #F59A83; */
      transform-origin: 44% 50%;
      animation: rotate 1.5s infinite linear; }

  @keyframes rotate {
    0% {
      transform: rotate(0); }
    100% {
      transform: rotate(360deg); } }

Answer №1

When it comes to adding a spinner, you're currently using <svg> and <use> tags while attempting to implement a .PNG file. In order to properly display the spinner, consider either using a regular img tag or make sure to utilize the <svg><use> tags correctly.

To address this issue, I recommend adjusting your code like so:

<svg>
    <use xlink:href="path/to/svg/file.svg#SVG_ID"></use>
</svg>

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

Explorer not displaying or loading jQuery/Ajax content

Currently, I have been experimenting with a template heavily reliant on jquery and javascript. My main focus lately has been learning more about jquery and javascript. You can find my site at . The functionality of the site is smooth in Firefox and Safari, ...

Extracting information from a JSON file using React.js

I have a JSON file named data.json in my React.js project: [{"id": 1,"title": "Child Bride"}, {"id": 2, "title": "Last Time I Committed Suicide, The"}, {"id": 3, "title": "Jerry Seinfeld: 'I'm Telling You for the Last Time'"}, {"id": 4, ...

"Utilize the inline display property to keep elements hidden

I have created a template named 'aTemplate' using the following code: $.template('aTemplate', '<div id="someid" class="abc">' + .... '</div>' ); My goal is to make this div inline with other ele ...

Error: Unable to locate attribute 'indexOf' within null object in vuejs when using consecutive v-for directives

I've been struggling with this issue for hours. I'm using vuejs' v-for to render items in <select> element's <options>, but I keep getting a type error. I've tried changing the :key values, but it still won't rende ...

Looking for tips on AJAX question regarding web scraping!

Attempting to scrape data from this website -> Upon inspecting the XHR calls made by the site, it seems that the results are fetched through an AJAX call using this API: */queries?x-algolia-agent=Algolia%20for%20vanilla%20JavaScript%203.30.0%3BJ ...

How to efficiently load 3000 objects in Openlayers using IE8

One of my clients exclusively uses IE8 and is working with an openlayers map. He is trying to load 3000 polygons onto the map, which Chrome and IE9 can handle without any issues. However, IE8 freezes when attempting to load the objects. These objects are c ...

When using Angular $http.post, encountering issues with the 'Access-Control-Allow-Origin' header

I have developed two applications using nodejs and angularjs. The nodejs app contains the following code: require('http').createServer(function(req, res) { req.setEncoding('utf8'); var body = ''; var result = '&a ...

The modal box should adjust its height to perfectly accommodate the content within

I'm in the process of developing a straightforward modal (popup) window, using as few lines of code as possible... just the basics. The modal has a maximum width of 650px and its height adjusts to fit the content. In case the content exceeds the avai ...

Using JavaScript, you can manipulate the position of a line on a canvas to

I want to create a feature where users can manipulate lines on a canvas by skewing them. This means they would be able to drag one end point of the line to a desired point on the same x-axis using JavaScript and HTML5 canvas. Can someone please provide g ...

Choose an element on a webpage by leveraging the power of Selenium

When working with Selenium in FireFox, I encountered an issue while trying to select specific fields on a webpage. The HTML pages I am referring to are available at the following links: Sample HTML Page, another sample page. The code snippet I used is sh ...

Getting JSON with duplicate keys in JavaScript can be achieved by parsing the data using a custom function

I am attempting to retrieve JSON from a URL, but I have encountered an issue where the response object is removing duplicate keys. Is there a way to fetch the JSON without eliminating these duplicates? Below is my JavaScript code: $('document'). ...

Customize the X and Y position of the CSS background with specific degrees

Looking for help customizing the background position in a PSD image to adjust the slope at the top, right-left side, and bottom. Here is my PSD: https://i.stack.imgur.com/Jr4h7.png Below is some of my CSS code: html{ background:#aea99f; } body{ backgroun ...

How do I extract a parameter when passing it to a promise in NodeJS?

Let me simplify this query. I need to fetch a parameter used in a promise. Here's the gist of the code: function foo(param) { return fromPromise(blabla, blabla2, param) .then((res) => { return res }).catch((error) => { console.log( ...

Anticipate that the function parameter will correspond to a key within an object containing variable properties

As I develop a multi-language application, my goal is to create a strict and simple typing system. The code that I am currently using is as follows: //=== Inside my Hook: ===// interface ITranslation { [key:string]:[string, string] } const useTranslato ...

Open the overflow div within a table data cell

My goal is to create a drag-and-drop schedule tool similar to Fullcalendar. I have decided to use a table layout with a rectangular div inside each TD cell to represent tasks. <table onDragEnd={dragend}> <tr> <th>0</th> ...

Iterate over rows in a b-table component in Vue

In the context of Vue bootstrap, a b-table consists of a list with an unknown number of rows. The requirement is to display a remove button only if the email in the row matches that of the currently logged-in user. This functionality currently works for a ...

Unable to retrieve custom date picker value with React Antd

I have implemented a custom datepicker for entering dates in the 'MMDD' or 'MMDDYY' format. The date value is stored in state and used in the datepicker component as a controlled component. However, upon form submission, the datepicker ...

Issue with MUI Grid item not functioning properly when using overflowY: "auto"

I am encountering an issue while using MUI with React. I have a <Paper> element wrapping a <Grid> with 3 children elements. The problem arises when I set the overflowY property of the bottom grid item to "auto" - instead of showing the scroll b ...

using ajax to fetch a file from laravel

My goal is to download a file by sending necessary parameters through an ajax request. In the process, I saved the output file in the public/exports directory and attempted to redirect to that file path in the success callback. public function downloadRe ...

Looking for a specific Greek symbol within a JavaScript string

I'm currently attempting to find a solution for replacing a Greek letter within a string with another character. For instance: value = "Hello μ!"; value.replace("μ", "You"); alert(value); //Expected result: Alerted value should be "Hello You!" Re ...