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

How to swap one image for another using jQuery on click

I have a question about updating images on an HTML page using jQuery. Below is the code I am currently using: $(document).ready(function() { $("#img-1").click(function() { var imgsrc = $(this).attr('src'); $(".click-img").attr('s ...

Issue encountered: Unable to load resource - ajax file upload failed due to net::ERR_SSL_BAD_RECORD_MAC_ALERT error

I've implemented an AJAX form file upload using jQuery. After testing my code across multiple computers and browsers, I've encountered an issue on one Windows 8 machine running Chrome where the upload functionality fails with the following error ...

How to add an 'alt' text tag to a background image sprite

I have a button that opens a new browser window, so I've added alternate_text and title tags to notify the user that a NEW window will open when hovered over. <img class="mp3PlayBtn" alt="Mp3 player opens in popup window" title="Mp3 player opens i ...

Please enter only numerical values using jQuery

Currently, I am facing a slight issue. My goal is to only run the code when the input characters are numbers. This is the snippet of code I have been working with: $(".jq-sales, .jq-variablecosts, .jq-fixedcosts, .jq-additional-sales, .jq-sales-units, .j ...

Function in React not being successfully passed down between functional components

I have been accustomed to using class components and now I am transitioning into functional components in order to become more proficient with hooks. However, I have encountered an issue where I am struggling to pass a function from one functional compone ...

The canvas's document.getElementById function is unable to find any matching element,

Hello everyone, I am currently diving into the world of javascript and trying to expand my knowledge. However, I have encountered a problem that has me stumped, and I could really use some assistance. While exploring, I came across this page: http://www.w ...

"Utilizing jQuery AJAX to enable multiple file uploads with specific file extensions

I've been facing an issue with uploading multiple files using jQuery and AJAX. The problem arises when I attempt to submit a PNG or JPG file, but it fails to submit and instead alerts me to "Please Upload File" even though a file has been selected. ...

Using jQuery to Retrieve the HTTP Status Code in the $.ajax.error Function

Currently, I am utilizing jQuery for an AJAX request. Depending on whether the HTTP status code indicates a 400 error or a 500 error, I wish to execute different actions. How can I go about achieving this? $.ajax({ type: 'POST', url: &ap ...

Receiving a JavaScript function's output with Python Selenium

Currently, I am in the process of scraping data from a specific webpage. The focus is on extracting the return string value from a Javascript function snippet. The target value to be extracted is indicated as "2227885" Attempting to achieve this ...

Avoiding HTML code within XML

I'm currently experiencing an issue with an invalid XML character appearing during interaction with a SOAP web service. When sending a formatted HTML message to a specific web service, I encountered a failed message that read as follows: Fault messa ...

AngularJS version 1.5.11 experiencing issues with ng-repeat functionality

Having an application built on angularJS v1.5.11, I encountered a major issue while attempting to use ng-repeat in a table format like below: <tbody> <tr ng-repeat="score in data.result"> <td ng-repeat="item in score"> {{ item }} & ...

When using Jest, the mongoose findOneAndUpdate function may return null values for both error and document

I've been struggling with Mongoose's findOneAndUpdate method as it doesn't seem to provide any useful information. I have tried accessing the Query returned from calling it (stored in updatedUser), but all it returns is null. Adding a callba ...

Troubleshooting: Angular 6 Renderer2 Issue with Generating Dynamic DOM Elements for SELECT-Option

Currently, I am attempting to dynamically create a select option using Renderer2. Unfortunately, I am facing difficulties in creating the <Select></Select> element, but I can confirm that the <options> are being successfully created. Due ...

Combining the inline JavaScript linting tool ESLint with the popular Airbnb configuration and Facebook

In my current project, I am utilizing ESLint and looking to incorporate Facebook flow. However, I am encountering warnings from ESLint regarding flow type annotations. Within the project root directory, I have both .flowconfig and .eslintrc files present. ...

Refresh Ajax/Javascripts following the loading of new data with .html() function

My website has a page that utilizes an ajax function to load data into the page. The ajax function is as follows: $(document).ready(function(){ function loadData(page){ $.ajax ...

Angular: Maximizing Input and Output

I'm having trouble with the function displaying within the input field. My goal is to simply allow the user to enter a name and have it displayed back to them. HTML: <div ng-app = "mainApp" ng-controller = "studentController"> <tr> < ...

Issue with Material UI Textfield functionality on mobile Safari browser

UPDATE: Resolved the problem by including this code in index.css input { -webkit-user-select:text;} In my application, I am using a Material UI box that contains text fields with an onChange handler. While the TextFields function correctly on most bro ...

Conflicting Angular components: Sorting tables and dragging/dropping table rows

In the current project I'm working on, I've integrated both angular table-sort and angular drag-drop. However, I ran into an issue where dragging a row and attempting to drop it onto another row causes the table sort to forcefully rearrange the r ...

Dynamically hiding elements within tabs using jQuery

Previously, I created a functionality for handling a single set of tabs. However, as the application has expanded, this functionality is no longer sufficient to accommodate multiple sets of tabs. The initial function looked like this: var iconTabs = func ...

Facing issues with ReactCSSTransitionGroup as transitionAppear feature is not functioning

I'm having trouble with the appearance and disappearance of notifications. The transitionAppear property doesn't seem to be working as expected. I'm adding the notification popup item to the onBlur event. The animation for the leave event wo ...