Conceal the object, while revealing a void in its place

Is there a way to hide an image but keep the containing div blank with the same dimensions? I want it to appear as if no content was there, maintaining the original width and height.

For example: http://jsfiddle.net/rJuWL/1/

After hiding, "Second!" appears before "First!", but I would like it to display as: First! (blank) Second!

HTML

<html>
<body>
    <div>First!</div>
<div class="loading">
<img id="loading" src="http://preloaders.net/preloaders/284/preview.gif" class="none"/>
    <div>Second!</div>
</div>
</body>

CSS

.none{display:none}
.loading{width: 32px;height:32px;}

Javascript

showLoading();    
function showLoading() {
  $("#loading").hide();
  $("#loading").show().delay(2500).fadeOut('10');
}

Answer №1

Instead of using display:none, try using visibility:hidden

By changing the CSS property to visibility:hidden, the element remains in the DOM flow while appearing as if its opacity is set to 0.

Check out this quick demo showcasing how to use fadeOut: http://jsfiddle.net/AlienWebguy/5cwE7/

Answer №2

To create a fading effect, I would utilize opacity.

showLoading();    
function showLoading() {
  $("#loading").fadeTo(0,0);
  $("#loading").fadeTo(0,1).delay(2500).fadeTo(10,0);
}

In the code snippet above, the first 0 represents the duration while the second one indicates the opacity. Use 1 for showing and 0 for hiding.

However, the logic in your code is questionable. Why hide it, then instantly show it, only to wait 2.5 seconds before hiding it again?

I believe that the initial hiding step is unnecessary (the first line of the showLoading() function in my version of the code)

Alternatively, you may consider using .css("opacity",0) instead of .fadeTo(0,0), as it is likely more efficient.

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

Utilizing Async/Await in conjunction with Vuex dispatch functionality

I'm currently working on creating a loader for specific components within my application. Here is the code snippet for one of my components: mounted() { this.loading = true; this.getProduct(); }, meth ...

Adding a Close Button to a MaterializeCSS Card or Card-Panel

Hey everyone! I'm looking for guidance on how to add a close button (x) to a card or card-panel in MaterializeCSS. While Bootstrap offers an Alert component, unfortunately MaterializeCSS does not have one readily available. Does anyone know of a wor ...

Creating a grid layout similar to Tumblr using HTML and CSS

Struggling all day to figure out how to create a Tumblr-style grid for my website, I'm reaching out here for some assistance. Here is the page: I have a grid of images on my project page that initially looked fine, but as I try to add new elements, i ...

The size of my React Native app is significantly larger than expected once installed

I recently developed a React Native app, and while the release APK size is only 28 MBs, I was shocked to see that the storage size is a whopping 62 MBs. I am desperately looking for a solution as I need to deliver this project soon. Please help me resolv ...

Changing Settings on the Fly with JQuery

I am facing an issue with a table that has values generated dynamically using PHP, such as id and name attributes (e.g. id="question_". My challenge is how to set an element attribute considering this dynamic nature. For instance, I need to update the tex ...

Combining ASP.NET with jQuery to create dynamically generated HyperLink controls

My ASP.NET application includes HyperLink elements that are dynamically generated based on database values. When a user clicks one of these links, a jQuery dialog box appears for editing. The issue arises when trying to save the modified values back to the ...

Ajax causing unreliable posts

I am facing an issue with sending and receiving data in my mobile application. I currently use the jquery $.post function, but it seems to be quite unreliable. Issue: Occasionally, about 1 out of 10 times, the POST request is sent successfully, but the ca ...

Unable to retrieve or remove cookie sent from Express on client side

My Express server is sending a cookie to the client that is not httpOnly. Despite this, the client is unable to access the cookie through document.cookie or see it in the Application tab on chrome dev tools. Interestingly, I am able to view the cookie in C ...

Sublime snippet for Jquery $(document).ready() fails to activate

I recently created a custom snippet in Sublime Text for the jQuery document ready function. However, I am experiencing an issue where the tab trigger appears in a popup but when I press enter or tab, no code is generated. Even after restarting Sublime mult ...

Expand Navigation Bar upon Hover

My goal is to recreate a Navigation Bar similar to the one found on this website: I want the Navigation Block to expand and show Menu Items when hovered over, just like the example on the website mentioned above. I've attempted to use Bootstrap and ...

Encountering issues when passing a string as query parameters

How can I successfully pass a string value along with navigation from one component to another using query parameters? Component1: stringData = "Hello"; this.router.navigate(['component2'], { queryParams: stringData }); Component2: ...

Version 5.3 of Laravel combined with Vue 2

Working with Vue 2 in a fresh Laravel 5.3 project, I'm faced with a challenge regarding binding a URL in the Laravel format. I've extracted some configuration rows from a database and my goal is to iterate over them to display the data, followed ...

Creating a mobile-friendly split column layout with Bootstrap 5

I have a similar question to the one posed in this thread How to split Bootstrap column in mobile mode, but I am working with Bootstrap 5 and the previous solution using float: right no longer works due to flexbox. On desktop, I have two columns and I wan ...

php modes breaking away from traditional php

My recent inquiry was regarding the distinction between HTML and PHP separation. While tutorials and examples often mention this concept, I have realized that it goes beyond what most people talk about - specifically relating to PHP modes. Is there a need ...

Utilize the JSSOR Slider to dynamically pull images from an online album, such as by integrating with an RSS Feed

My main motivation for exploring this possibility is the negative impact that loading images into the slider has on my website's performance. Is there a method to import images from an externally hosted album, such as Google Picasa albums (or any othe ...

Avoid using <input oninput="this.value = this.value.toUpperCase()" /> as it should not convert the text displayed on the "UI", rather it should send the uppercase value

<input oninput="this.value = this.value.toUpperCase()" type="text" id="roleName" name="roleName" class="form-control width200px" [(ngModel)]="role.roleName"> Even though the UI is changing ...

The checksum verification encountered an error during the installation process of the npm package weexpack

I am encountering an issue while trying to install weexpack. It seems that the sha1 checksum verification is failing. npm install -g weexpack npm ERR! code EINTEGRITY npm ERR! sha1-33w+1aJ3w/nUtdgZsFMR0QogCuY= integrity checksum failed when using sha1: w ...

IntelliJ has removed the connect-flash plugin, preventing me from reinstalling it

Learning node.js is new to me and I encountered a strange issue. While working on implementing login functionality with passportjs, I faced an error where req.flash() was not functioning properly. Oddly enough, it was working fine yesterday when I used it ...

Exploring Methods to Iterate through an Object Utilizing Two Arrays

Attempting to iterate through states passed as props in another component state = { question:[firstQ, secondQ, thirdQ], tag:[[1,2,3],[4,6],[a,b,c,d]] } I aim to display it on the next Componet with a pattern like: FirstQ [tag1] SecondQ ...

Select a random option from the dropdown menu

I have the following script: <script> function $(id) { return document.getElementById(id); } function getImage() { $('loader').src='/misc/images/loading.gif'; var url = "http://mouse ...