Expanding circle with CSS borders on all edges

My goal is to create a background reveal effect using JavaScript by increasing the percentage.

The effect should start from the center and expand outwards in all directions.

Issue: The percentage increase currently affects only the bottom and not the top as intended.

Seeking Alternatives: If there is an easier method to achieve this effect of revealing a background image within a circle, I would greatly appreciate any suggestions.

Current Attempt:

// Implementing the script here for achieving the desired effect
window.onload = function() {
  var counting = false;

  function start(count) {
    if (!counting) {
      counting = true;
      $('.preloader_meter').width(count + '%');
      $('.preloader_meter').height(count + '%');
      var timer = setInterval(function () {
        if (count >= 0) {
          $('.preloader_meter').width(count + '%');
          $('.preloader_meter').height(count + '%');
          count++;
        } else {
          clearInterval(timer);
          count = arguments[0];
          counting = false;
        }
      }, 100);
    }
  }

  start(0);

};
// CSS code for styling the preloader element
body.preloader {
  background: none;
  visibility: hidden;
}
#preloader {
  font-family: Arial;
  font-size: 12px;
  visibility: visible;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  height: auto;
  margin: 0;
  z-index: 9999999999;
}
/* Other CSS styles continue ... */
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<div id="preloader" class="preloader_progress" style="background-color: rgb(38, 45, 51);">
  <div class="preloader_loader">
    <div class="preloader_meter" style="width: 0%; height: 0%;"></div>
  </div>
  <div class="preloader_percentage" id="log">85%</div>
</div>

Answer №1

To adjust the position of a circle, you must modify its top property based on its size.

$('.preloader_meter').css('top', 50 - count/2 + '%');

window.onload = function() {
  var counting = false;

  function start(count) {
    //console.log(counting);
    if (!counting) {
      counting = true;
      $('.preloader_meter').width(count + '%');
      $('.preloader_meter').height(count + '%');
      var timer = setInterval(function() {
        if (count >= 0 && count <= 100) {
          $('.preloader_meter').width(count + '%');
          $('.preloader_meter').css('top', 50 - count/2 + '%');
          $('.preloader_percentage').html(count+'%');
          $('.preloader_meter').height(count + '%');
          count++;
        } else {
          clearInterval(timer);
          count = arguments[0];
          counting = false;
        }
      }, 100);
    }
  }

  start(0);

};
body.preloader {
  background: none;
  visibility: hidden;
}
#preloader {
  font-family: Arial;
  font-size: 12px;
  visibility: visible;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  height: auto;
  margin: 0;
  z-index: 9999999999;
}
#preloader.preloader_number:before,
#preloader.preloader_progress:before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-image: -webkit-radial-gradient(circle, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.01));
  background-image: -moz-radial-gradient(circle, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.01));
  background-image: -ms-radial-gradient(circle, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.01));
  background-image: -o-radial-gradient(circle, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.01));
  background-image: radial-gradient(circle, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.01));
}
#preloader.complete {
  opacity: 0;
  -webkit-transition: opacity 0.2s linear 0.5s;
  -moz-transition: opacity 0.2s linear 0.5s;
  -ms-transition: opacity 0.2s linear 0.5s;
  -o-transition: opacity 0.2s linear 0.5s;
  transition: opacity 0.2s linear 0.5s;
}
#preloader.preloader_line {
  height: 2px;
  bottom: auto;
}
/* Number Mode */

#preloader.preloader_number .preloader_percentage {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  margin: auto;
  width: 100px;
  height: 100px;
  border-width: 1px;
  border-style: solid;
  border-radius: 50%;
  line-height: 100px;
  font-size: 20px;
  font-family: Impact, Arial;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
  text-align: center;
}
#preloader.preloader_number .preloader_percentage > div {
  position: absolute;
  top: -2px;
  right: -2px;
  bottom: -2px;
  left: -2px;
  border: 4px solid transparent;
  border-left-color: #FFFFFF;
  border-radius: 50%;
...
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<div id="preloader" class="preloader_progress" style="background-color: rgb(38, 45, 51);">
  <div class="preloader_loader">
    <div class="preloader_meter" style="width: 0%; height: 0%;"></div>
  </div>
  <div class="preloader_percentage" id="log">85%</div>
</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

The perplexing quandary of validating email uniqueness in AngularJS

My form in Angular needs to be able to detect duplicate user emails. The code I'm concerned about can be found here: http://plnkr.co/edit/XQeFHJTsgZONbsrxnvcI This code includes the following directives: ngFocus: tracks whether an input is on focu ...

At times, the animation in SetInterval may experience interruptions

I have created an animation using a sequence of images. The animation runs smoothly with the setinterval function, but for some reason, it occasionally pauses. I've shared a fiddle where you can see this pause happening. Click Here to See the Unwante ...

Guide to integrating numerous product filters for an ECommerce platform using Spring Boot, JavaScript, Ajax, and MySql

Currently, I am developing an E-Commerce Web App using Spring Boot which includes a feature to add multiple product filters. The user can select checkboxes corresponding to their preferences for filtering or searching products from the store. However, I am ...

Error encountered when uploading mp3 file to S3 node due to size limitation

Currently, I am utilizing Node to transmit mp3 files to Amazon S3. However, after uploading the file, it shows a size of 9.0 Bytes and when attempting to play the audio from the public URL, it does not work as expected. Here is my current code snippet: rou ...

The functionality of Selenium's get(link) feature appears to be experiencing issues

Recently, I wrote a simple piece of code using selenium to open a webpage. from time import sleep from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.by import By import warnings warnings.simp ...

Is there a way to directly access the React component that was clicked?

I'm looking to dynamically change the class of a component when clicked. By using state to create a new component with properties such as name and done (initiated as false), which are then added to the todos array, I want to find out how to identify t ...

Determine if the browser displays <select multiple> as a modal dialog

Is it possible to use JavaScript to detect whether a specific browser displays a focused <select multiple> element as a popup or strictly as an inline box? On certain platforms, like the Android Browser and iOS Safari, the appearance of a popup can ...

Ways to enhance widget titles with borders on Blogger

As a Blogger user, I am looking for guidance on how to add a border around the title of each widget/gadget. When I place widgets such as About Me, Follow Us, etc., in my sidebar, I want them to have borders like in this image. While I know how to customize ...

Utilizing Google Chrome Extension: Sharing variables between injected scripts via chrome.tabs.executeScript to another script injected in a similar manner

Can anyone help me with a coding challenge? I have two scripts injected in my popup.js and I need to make a variable defined in one script accessible to the other. Here's how I'm injecting the scripts: let sortFunction = function (goSortParam) { ...

What is the best way to clear a THREE.JS scene?

I am exploring methods to remove all objects from a scene without affecting the scene structure. I understand that naming each object individually allows for selective deletion by name. But, I am searching for a fast approach to clear a scene of all obje ...

AngularJS not displaying loader during AJAX request

While utilizing ajax requests with $http, there seems to be a delay due to the server operation taking longer than expected. I have implemented a loader to display while processing the request, but unfortunately it is not showing up on the page. Even after ...

Updating the style of a CSS element using Python Selenium

Is it possible to change the css element style using Python Selenium during automation to increase the height of the page? The structure of the element in the HTML is as shown below: <div style="overflow-y:scroll;overflow-x:hidden;height:150px;&quo ...

What is the process for establishing the admin's username and password using a database table?

I recently developed a website that includes a login form for the administrator. I have set up an admin table in my database and filled it with values. However, when I attempt to log in, the password is not being recognized. Here is a snapshot of my curren ...

Uncovering the secrets of extracting form parameters with jquery.ajax in asp.net

In search of a method to extract form parameters in C# similar to Java's request.getParameter("blah"). I am currently serializing my form with jQuery and sending it to a web method, but I need assistance in extracting the data. Using ajax. $("#btn" ...

Styling conditionally with Dash Bootstrap using an IF statement

I am looking to implement a feature where text in a column is displayed in two different colors based on its value, using Dash bootstrap and various HTML components. For example, consider the following table: Value Yes No Yes Yes No The goal is to displa ...

How can I prevent a CSS class from being rendered in a specific view within MVC?

My knowledge of CSS is quite limited and I am fairly new to it. In my MVC application, I am using a theme that relies on Bootstrap. In the _layout view of my application, I have the following code: <div class="container body-content"> @Html.Par ...

String variable representing the name of a React element

As I was reviewing the source code of a React UI library, I stumbled upon an interesting code pattern that I will simplify here: function Test() { let Button = "button"; // ... return <Button>Click me</Button>; } I'm curious about ...

How selection.join behaves when every node contains child elements

I have been following the amazing tutorial on to learn more about the join paradigm. Everything was working fine until I tried to make each node more complex by adding a group with text inside. The main group gets updated, but the child one does not. Sn ...

Using CSS to create a color combination of black with varying opacities

I attempted to achieve a black color by blending together the colors red, yellow, and blue in CSS, but encountered an issue... Is there a way to create black color using opacity? ...

Encounter a snag while using Chrome to access an external API through jQuery

I am currently utilizing jQuery to make a request to an external API via AJAX. $.ajax({ url: https://exampleAPI, method: "GET", contentType: "text/plain", dataType: "jso ...