Showing a Div after a designated time of page loading: A simple guide

While I have a good understanding of CSS, Javascript is still new territory for me. I could use some guidance on the following task.

My goal is to display a fixed div at the bottom of the screen, but I only want it to appear after a specific delay, say 10 seconds. How can I achieve this using the code below?

CSS

.bottomdiv
{
   position: absolute;
   left:    0;
   right:   0;
   z-index : 100;
   filter : alpha(opacity=100);
   POSITION: fixed;
   bottom: 0;
}

HTML

<div class="bottomdiv">
    <iframe src="http://example.com" width="990" height="110" scrolling="no"></iframe>
 </div>

Your assistance would be greatly appreciated. Thank you.

Answer №1

If you have the jQuery tag in your question, chances are you're utilizing jQuery. Here's a handy snippet for that:

// Execute this code when the DOM is fully loaded:
$(document).ready(function(){
   // Add a 10-second delay before executing the action
   setTimeout(function(){
      // Show the div with the class "bottomdiv"
      $(".bottomdiv").show();
   }, 10000);
});

Don't forget to include the "display: none;" property in your div's CSS class.

Answer №2

To delay a function in JavaScript, use Timeout. I have set it to run after 5 seconds. Here is a working example on JSFiddle. It's recommended to add or remove classes for these types of activities:
Check out the fiddle
HTML

  <div class="bottomdiv hide" id="footer">
   <iframe src="http://example.com" width="990" height="110"  scrolling="no"></iframe>
  </div>

CSS

.bottomdiv
{
 position: absolute;
 left:    0;
 right:   0;
 z-index : 100;
 filter : alpha(opacity=100);
 POSITION: fixed;
 bottom: 0;
}
.hide {
 display: none;
}

JS

setTimeout(function(){
 document.getElementById('footer').classList.remove('hide');
}, 5000);

Answer №3

To make some modifications in your css, consider the following adjustments:

.footer-section{
   left:    0;
   right:   0;
   z-index : 100;
   filter : alpha(opacity=100);
   position: fixed;
   bottom: 0;
   display: none
}

Additionally, as per recommendations from my acquaintance, reveal the div after 10 seconds using JavaScript:

$(document).ready(function(){
   setTimeout(function(){
      $(".footer-section").show();
    }, 10000);
});

Answer №4

Here's an example that demonstrates how to show a hidden element using vanilla JavaScript, without relying on jQuery:

<!DOCTYPE html>
<html>
<body>
    <div id='example' style='display:none'>Click me</div>

    <script>
        window.onload = function () {
            setTimeout(showElement, 5000);
        }
        
        function showElement() {
            document.getElementById('example').style.display= "block";
        }
    </script>

</body>
</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

Utilize Vue 3 for setting up reactive fetching with asynchronous JSON handling

I recently upgraded to Vue 3 and I'm trying to populate a reactive object by fetching data from a JSON API. Here's how my component looks. Surprisingly, I am not encountering any errors but the expected results are not showing up either. <tem ...

The usage of $('').switchClass in IE8 may cause an error when the switched class includes a color property

I have the following unique css classes .swap-format{ background-color: green; } .swap-format1{ background-color: orange; } .swap-format2{ color: purple; } Using these classes, I want to create an animation on the given div <div id="swap-clas ...

Understanding the implementation of public and private methods in mixins in Vue2

While I've come across documentation on the following implementation, I find myself struggling to visualize how it can be executed. // A more advanced alternative! var myGreatMixin = { // ... methods: { publicMethod() { // ... myPr ...

Tips for creating multiple diagonal lines with CSS and HTML

Is there a way to create multiple diagonal lines within a rectangle using CSS and HTML from the start? I am interested in incorporating diagonal lines at the onset of the rectangle. Here is an example code that displays the rectangle: <div className={ ...

Can the position of the popover be customized using the right and top properties?

Utilizing Bootstrap popover within a gantt chart, I am dynamically adjusting the position of the popover based on mouse hover. popover.css('left', event.pageX + 'px'); popover.css('top', event.pageY+ 'px') However, ...

Utilizing the state as a condition within the useEffect to update the component

Is there a way to automatically hide the mobile menu when the URL changes in ReactRouter? I have noticed that I get a warning for not tracking mobileOpen as a dependency, but strangely the code still works fine. const Navbar: React.FC<Props> = props ...

How to use puppeteer to extract images from HTML that have alt attributes

<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12 nopadding text-center"><!-- Start Product Photo --><div class="row"><img src="/products/ca/downloads/images/54631.jpg" alt="Product image 1">&l ...

Having trouble with JQuery's .prop function not unchecking a checkbox?

I have been experimenting with different solutions in order to uncheck a checkbox when another checkbox is checked. Unfortunately, none of the methods I've tried seem to be working effectively... Currently, my code looks like this: $("#chkBox1").cli ...

struggling to get the basic .gif loader to function properly

I recently designed a website with multiple images on certain pages, and I wanted to incorporate a loading gif that shows up in a specific div (#carousel) while the images load. I found a super simple guide on a website that I attempted to follow, but unfo ...

jQuery-powered web application, experiencing compatibility issues when deployed on Windows Server 2003 and Internet Explorer

While developing a web application on XP and FF (with occasional IE checks through IE 8), I encountered an issue when deploying it to a WS 2003 site running IE 7. My jQuery code for dynamically sizing divs does not execute, even when explicitly stating div ...

What is the best way to eliminate the white space between two sections?

I am currently utilizing Bootstrap 4 along with a custom CSS stylesheet for my website structure. Here is the layout: <header> <!-- content in header (fixed) --> </header> <main role="main" class="container-fluid"> <!-- ...

What is preventing me from modifying the input file name in PHP?

After executing the code below, an error message pops up: "Notice: Undefined index: uploadFile in C:\xampp\htdocs\ImageTest\processImage.php on line 17" However, when I switch every occurrence of 'uploadFile' with 'fi ...

When attempting to send data from Ajax to PHP as JSON, an error occurs and the data transmission fails

When attempting to send data as JSON, an error response is received stating: SyntaxError: Unexpected token < in JSON at position 0. If the data is sent as text, it successfully reaches PHP, but PHP does not respond accordingly. AJAX/JavaScript using J ...

Sending arguments to Angular UI router template

My angular ui router is changing states/views as: $stateProvider .state({ name: 'home', url: '/', template: '<home-view></home-view>', }) Is it possible to ...

css based on the current time in the United States

I have a working code that currently reads the user's computer time, but I specifically need to get the hours from the USA regardless of the user's location. The CSS should be applied based on USA time. <script type="text/javascript"> dat ...

`Can controllers be included in route or template definitions?`

When it comes to defining a route with a template, there are two main ways to set the controller for the view: In the route: $routeProvider .when('/phone/:phoneId', { controller: 'PhoneDetailController', templateUrl: &ap ...

Exploring the gridview with JQuery to iterate through and verify if any checkboxes have been selected

I am currently working on a jQuery-based application. In this application, I have an ASP.net GridView that contains checkboxes in each row. My goal is to determine whether any of the checkboxes are checked or not. Below is the code snippet where I loop thr ...

Loading default values into HTML/Jade in an Express/node.js web application

My web application is developed with Express for node.js. I have utilized Jade template files for the HTML views. On one of these views, I want the input fields to be pre-filled with data. The data is stored in a mongodb session store, as well as in anot ...

The perplexing configuration of a webpack/ES6 project

I am currently in the process of setting up my very first ES6 and webpack "application" where I aim to utilize classes and modules. However, each time I attempt to transpile the application using the webpack command, I encounter the following error: $ web ...

Three.js fails to render Blender model

After creating a basic blender model, I exported it as a .json file using the three.js plugin. However, when attempting to import the file into my project, I encountered some difficulties. As file transfers are restricted through file://, I uploaded the f ...