Click the button to trigger a loading popup, followed by a change in the text displayed on

I have a button that triggers a popup box when clicked. However, I want to add a loading circle with text underneath before the popup appears, and for it to display after 3 seconds. Is this doable?

Here is my current code snippet:

<a href = "javascript:void(0)" onclick = "document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'">
<div class="btn">Win!</div>
</a>
<div id="light" class="white_content">Congratulations, you've won!<br>Claim your prize now by completing a short survey:<br>
<input type="submit" value="Complete Survey" onclick="location.href='http://mobverify.com/cl.php?id=5c78fd59851bf0c4867c008c9882d808'"> 
<a href = "javascript:void(0)" onclick = "document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'"></a>
</div>

Current style of the popup:

.white_content {
        display: none;
        position: absolute;
        top: 25%;
        left: 25%;
        width: 50%;
        height: 150%;
        padding: 16px;
        border: 2px solid white;
        background-color: #2e3141;
        z-index:1002;
        overflow: auto;
        text-align: center;
        color: white;
        border-radius: 30px;
    }

Answer №1

To incorporate this style into your project, simply insert the provided CSS snippet below:

.btn {
   width: 250px;
   height: 250px;
}
.btn:active {  
   background: url(http://www.example.com/image.gif) no-repeat; 
}

Answer №2

If you want to display the loader image upon clicking and then open a popup after a delay of 3 seconds, you can achieve it using a timeout function.

Here is a simple example:

var delay;

function displayLoader(){
  document.getElementById('loader').className = '';
delay = setTimeout(openPopup, 3000);
  return false;
}

function openPopup() {
  document.getElementById('light').style.display = 'block';
  document.getElementById('loader').className = 'hidden';
  clearTimeout(delay);
}

function closePopup() {
  document.getElementById('light').style.display = 'none';
  clearTimeout(delay);
  return false;
}
.white_content {
  display: none;
  position: absolute;
  top: 25%;
  left: 25%;
  width: 50%;
  height: 150%;
  padding: 16px;
  border: 2px solid white;
  background-color: #2e3141;
  z-index: 1002;
  overflow: auto;
  text-align: center;
  color: white;
  border-radius: 30px;
}

.hidden {
  display: none
}

#loader {
  background: url(http://www.pointoffshore.com/SiteAssets/loading.gif) no-repeat center center;
  height: 50px;
  width: 50px;
}
<a href="#" onclick="displayLoader()">
  <div class="btn">Win!</div>
  <div id="loader" class="hidden"> </div>
  </div>
</a>
<div id="light" class="white_content">Congratulations, you've won!
  <br>Claim your prize now by completing a short survey:
  <br>
  <input type="submit" value="Complete Survey" onclick="location.href='http://mobverify.com/cl.php?id=5c78fd59851bf0c4867c008c9882d808'">
  <a href="#" onclick="closePopup()">close</a>
</div>

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

Using TypeScript, let's take a closer look at an example of Angular

I am trying to replicate the chips example found at this link (https://material.angularjs.org/latest/#/demo/material.components.chips) using TypeScript. I have just started learning TypeScript this week and I am having some difficulties translating this co ...

Mysterious source utilizing leafletView for showcasing popups within the Angular Leaflet Directive

I've been attempting to implement a pop-up window on an Angular Leaflet map using Prune Cluster, but I keep running into an error stating that 'leafletView' is an unknown provider. Despite following the examples provided on this page, https: ...

Difficulty in locating elements within ngView-loaded elements using jQuery [AngularJS]

I am attempting to retrieve the offset().top of an element <div class='profile'></div> located within a ngView controlled by app.js. However, I encounter an error in the console: Uncaught TypeError: Cannot read property 'top&a ...

Exploring the functionality of the `super()` method in TypeScript

I'm trying to enhance the standard JavaScript Error class by adding another property called code, but for some reason, TypeScript is not allowing me to do so. Here is the code snippet: export class HttpError extends Error { public message: string ...

- shorthand CSS properties roster- index of abbreviated CSS attributes

I have created a JavaScript function that needs to extract CSS values, even those that may contain multiple values. For instance, margin:0 0 4px 12px; consists of four separate values (margin-top, margin-right, etc). Specifically, I am looking for a list ...

The JSON.stringify function encounters difficulties when trying to format an object into

Why does JSON.stringify refuse to format objects and keep everything on a single line? <!DOCTYPE html> <html> <head> <script> var obj = { "a" : "1547645674576457645", "b" : "2790780987908790879087908790879087098", "c" ...

Tips on creating a post that can be viewed exclusively by one or two specific countries

I'm stumped on how to create a post that is visible only to specific countries. How can I code it to determine the user's country without requiring them to make an account? Any advice or hints would be greatly appreciated. ...

Tips for updating mongoose user data with associated posts that share the same user id

As I dive into building my inaugural MERN application, a particular issue has arisen. The posts within the application contain the user id information: { "reward": { ... }, "_id": "5eb2d90d7d56c415cc4d5f97", "user": "5eabbb85b8814 ...

Customize Your Google Maps with Checkboxes for Style Options

Trying to make dynamic changes in the style of a Google Maps using checkboxes. Some checkboxes control colors of features, while others control visibility. Having trouble figuring out how to combine different features of styles since they are not strings ...

Capturing mouse clicks in Javascript: a guide to detecting when the mouse moves between mousedown and mouseup events

I have been working on a website that features a scrolling JavaScript timeline, inspired by the code found in this tutorial. You can check out the demo for this tutorial here. One issue I've encountered is when a user attempts to drag the timeline an ...

Retrieve events triggered by each element

Currently, my research centers around digital marketing and user experience. In order to gather the necessary data for this study, I must collect event logs from all components within a UI to create datasets on usability patterns. In a web interface, such ...

Having trouble including a YouTube iframe code within the document ready function

I am having trouble getting the youtube iframe API code to work properly within my $(document).ready() function. When I try to add the code inside the function, the player does not load. However, when I move the code outside of the document.ready, the play ...

What is the best way to ensure that only one of two textboxes is filled out in an HTML form?

Looking to create 2 fields that are mutually exclusive. One will be a FileField and the other a TextBoxField. Is there an HTML form template available for this specific scenario? I've scoured the web but haven't come across one yet. Apologies ...

Sending emails to multiple groups in Opencart can be easily achieved with the

I am interested in customizing Opencart's admin panel to allow for the selection of multiple customer groups when sending emails. However, I am unsure of where and how to make these modifications as I am relatively new to this type of task. https://i ...

Working with Vuex: Simplifying state management by accessing multiple state objects with a single update mutation/action

I am facing a challenge with updating objects containing different strings using a single mutation and action in my project. Currently, I am attempting to extract a string from an input field's value and name, using the name as the object property to ...

Is it normal for Node's console to not display all object properties?

After running some code, I noticed something peculiar. console.log(myURL); It seems that the extension property is missing: console.log(myURL.extension); However, when logging it on its own, the value appears correctly. The URL object was created ...

Merge identical year items into a single entity

I have an array of objects containing car data: [ { year: 2019, company: 'Toyota', quantity: '450' }, { year: 2019, company: 'Ford', quantity: '600' }, { year: 2020, company: ...

displaying a div upon checking the checkbox

How can I make a div push the content below it when it is in the show state? Currently, when I check the checkbox, the textarea covers the submit button, hiding it. Is there a way for the textarea to push the button down instead? You can find my code here: ...

Converting a 3D model from Unity to three.js for seamless integration

I am tasked with building a human body model in WebGL using three.js, but I only have a Unity model. Is there a way to export the Unity model as an object or something similar for this purpose? ...

Is there a variety of values for the POST value field?

Currently, I am working on a contact edit form. The entire form loads dynamically via ajax, appearing in a lightbox. The form is pre-populated with the existing contact's data. After clicking the edit button, jQuery scans for any changes in the for ...