Creating dynamic animations with CSS3 to make circles grow in size

I'm currently working on a project where I want circles to grow outwards from the center when the page loads, rather than from the top left corner. Here is the link to see what I have so far:

My goal is to achieve this effect using CSS, but I'm open to using JavaScript if it's more practical or stable.

Do you have any suggestions on how I can accomplish this?

Below is the CSS code I have for the animation:

.circle a {
  border-radius: 150px;
  color: #fff;
  height: 0;
  position: absolute;
  text-decoration: none;
  width: 0;
}

.circle a.grow {
  -webkit-animation-name: grow;
  -webkit-animation-duration: 2.2s;
  -webkit-animation-timing-function: ease;
  -webkit-animation-iteration-count: 1;
  -webkit-animation-direction: normal;
  -webkit-animation-delay: 0;
  -webkit-animation-play-state: running;
  -webkit-animation-fill-mode: forwards;

  -moz-animation-name: grow;
  -moz-animation-duration: 2.2s;
  -moz-animation-timing-function: ease;
  -moz-animation-iteration-count: 1;    
  -moz-animation-direction: normal;
  -moz-animation-delay: 0;
  -moz-animation-play-state: running;
  -moz-animation-fill-mode: forwards;

  animation-name: grow;
  animation-duration: 2.2s;
  animation-timing-function: ease;
  animation-iteration-count: 1; 
  animation-direction: normal;
  animation-delay: 0;
  animation-play-state: running;
  animation-fill-mode: forwards;
}

@-webkit-keyframes grow {
  0% { -moz-transform: scale(0); }
  100% { -moz-transform: scale(1); }
}

@-moz-keyframes grow {
  0% { -moz-transform: scale(0); }
  100% { -moz-transform: scale(1); height: 168px; width: 168px; }
}

@keyframes grow {
  0% { -moz-transform: scale(0); }
  100% { -moz-transform: scale(1); }
}

Answer №1

Check out this simple demonstration to see how it's done: jsfiddle.net/UxtJV/. With a touch of JavaScript, a class is added to create an animated circle. The properties being animated include the width, height, top, and left, with the element having position: relative.

div.circle {
    position: relative;

    width: 0px;
    height: 0px;
    top: 50px;
    left: 50px;

    -webkit-transition-duration: 2s;
    -webkit-transition-property: all;
    -webkit-transition-timing-function: ease-in-out;

    text-align: center;
    background: red;
    color: white;
    border-radius: 100%;
    padding: 20px;
    overflow: hidden;
}

div.circle.open {
    top: 0px;
    left: 0px;
    width: 100px;
    height: 100px;
}​

Answer №2

In order to achieve this, your animated sequence should include:

  1. expanding the width and height.
  2. shifting up and to the left.

It may require some effort, but it will deliver exactly what you requested.

Answer №3

Avoid using Jquery or Javascript in this scenario as you can accomplish the desired effect using only CSS.

Refrain from utilizing the position property on your animated elements to prevent sluggish animations. Instead, opt for the transform property for smoother performance.

<div class="circle__container">
  <a class="circle" href="#"></a>
</div>

/* The circle__container aids in centering the div on the page */
.circle__container { 
  position: fixed; 
  top: 50%; 
  left: 50%; 
  -webkit-transform: translate(-50%, -50%); 
  transform: translate(-50%, -50%); 
}

.circle__container a.circle { 
  display: block; 
  height: 168px; 
  width: 168px; 
  background-color: #fea733; 
  border-radius: 50%; 
  animation: growUp 2s 1.5s; /* Remove 1.5s if delay is not needed */
}


@keyframes growUp {
  0%  { transform: scale(0); }
  100% { transform: scale(1); }
}

This approach should suffice for your needs.

Answer №4

One suggestion is to experiment with integrating your animation and the translation property.

An alternative approach could involve using the following code snippet:

transform-origin: top right; /* Adjust values as needed */

This method was originally shared on this forum thread...

Answer №5

For those seeking a functional jQuery solution, look no further...

HTML

<div class=circle1></div>

CSS

.circle1 {
    position:absolute; top:50px; left:50px;
    width: 0px; height: 0px;
    border:1px solid red;
    padding:20px;
    border-radius:50%;
}

JS

$(".circle1").mouseover(function() {
      $(this).animate({top:"0", left:"0", width:"100px", height:"100px", opacity: 0}, 200);  
}).mouseout(function() {
      $(this).animate({top:"50px", left:"50px", width:"0", height:"0", opacity: 1}, 200);
});

Take a look at the live demo here - http://jsbin.com/esiLULEb/1/

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 delete an element from a session array using Jquery and Ajax techniques

In my table, each element in an array corresponds to a row. I'm attempting to delete an element when the delete image (with the id deleteRowButton) is clicked. Currently, nothing happens upon clicking the image. However, if I remove the line var index ...

Prevents side-to-side scrolling in the section while enabling scrolling up and down on the

I have a div on my website that allows for horizontal scrolling, while the entire page can be scrolled vertically. When the cursor is over a specific section, it disables vertical scrolling and enables horizontal scrolling within that section. I have imp ...

Flag is to be set while moving through the input fields

I am currently working on a form with multiple text fields and a text area. I have implemented a loop to go through each of these fields and check if there is a value present. If the field is empty, I set a flag to pass=false. On the other hand, if a value ...

Is it more effective to specify the class within the selector when using jQuery to remove a class?

Does including the class in the selector when removing a class using jQuery have any impact on performance or best practices? I'm curious if there will be any noticeable difference. For example, do you include it like this: $('#myList li.classT ...

Obtain JSON data instead of XML data from a web service through Ajax with the option 'contentType' set to 'false'

Upon making an AJAX call to send an image file to one of my web service (.asmx) methods, I encountered a problem where the web service returns XML instead of JSON. This issue arose because I needed to set the contentType to false, in order to successfully ...

Retrieving data from PHP using jQuery and JSON

Struggling to retrieve various variable outcomes from PHP using jQuery JSON. Encountering issues with null values appearing in the console (like in the title), causing script failures. Currently, attempting to fill input fields with data received from PHP. ...

Positioning absolute elements negatively in Firefox may cause unexpected behavior

I attempted to position an absolute element with a negative value, and it works perfectly in every browser except for Firefox. In Chrome, IE, or Safari, the blue handler box is correctly positioned in the middle of the top border. Is there a workaround to ...

What is the best way to align an image in the middle of an image slider within a Bootstrap

Struggling to align the image properly in a Bootstrap 5 image slider carousel: https://i.sstatic.net/upPza.png <div id="carouselExampleIndicators" class="carousel slide" data-bs-ride="carousel"> <div class=&qu ...

Attaching jQuery function to onready event or ajaxSuccess event

I'm looking to run code either when ajaxSuccess event triggers or on a page reload. How can I bind both of these events to the document? $(document).on("ready, ajaxSuccess", function() { //... }); The code above isn't functioning as expect ...

I want to save the pincode column from a datatable into a variable and then display it when a button is clicked

var pincode=$(this).closest('tr').children('td.pincode').text(); The code snippet above is functional for non-responsive datatable setups. However, it does not work in the responsive view of the datatable. Is there an alternative solu ...

Is there a way to show an XML string on my website in the style of StackOverflow's 'insert code' feature?

When using the DataContractSerializer to convert an object returned from a WCF call to XML, I encountered an issue where if I outputted the XML string directly to a label on a webpage, the browser would strip out the angle brackets. This got me thinking ...

Utilize Bootstrap's form-inline feature to arrange fields side by side in one neat

I am looking to customize my sign-in form layout by displaying the fields in a row next to each other rather than under each other. header: Update: I have successfully implemented this code <header class="navbar navbar-fixed-top navbar-inverse"> & ...

The Magic of jQuery Cross Site Fetch

It seems like this should be simple, but I am having trouble figuring it out... I'm using jQuery to fetch a remote page from a different server, grab the HTML content, and then insert that content into a hidden DIV. However, when I try to do this wit ...

Several radial progress charts in JavaScript

While attempting to recreate and update this chart, I successfully created a separate chart but encountered difficulties with achieving the second progress. The secondary chart <div id="radial-progress-vha"> <div class="circle-vha ...

Styling multiple divs using CSS

What is the method for attaching CSS to sp-copyright? <div class="container"> <div class="row"> <div id="sp-footer1" class="col-sm-12 col-md-12"> <div class="sp-column "> <span class="sp-copyright"> ...

When hovering over an image, the title will display in a distinct div

I'm completely new to jQuery and would really appreciate any help or advice you can give! I was able to get this code working on jsFiddle: http://jsfiddle.net/cakeeater/LUAtb/10/ All I need is for the title of an image to replace the text "Hello" wh ...

Resize the p-accordion within a p-splitter using PrimeNG programmatically

Please find the code for my component below: In this component, I have a p-splitter that is divided into 3 sections. Each section contains a p-accordion, which in turn includes a p-table. <div class="card w-full"> <p-splitter [p ...

Why isn't Google Map showing up in my HTML <div> section?

I am currently working on a web page that consists of two containers. The mainmapdiv container covers the entire page, while the mainhomediv container is positioned on top of the mainmapdiv. My goal is to hide the mainhomediv container and show a Google Ma ...

Concealing elements larger than a specified variable within a table using JQuery

<input type="checkbox" id="canafford"></input> My goal is to create a feature where only upgrades that the user can afford will be displayed when they check a specific checkbox. Below is an example of one part of my upgrades code: <tr id=" ...

hover effect on CSS dropdown menu that displays all drop-down options

I found this awesome CSS menu on Fiddle that I'd like to share with you: http://jsfiddle.net/DenErello/pQhpu/ Here's the CSS code: .Menu { background-color: #3b69a2; height: 30px; } .Menu, .Menu li { list-style: none; padding: 0; margin: 0; } . ...