Create a circular motion animation from scratch

Looking to create an animation resembling a "firework" that bursts around a circular image, with 10 rays spaced evenly like wheel spokes. Each ray extends, the tail catches up to the head, and then disappears. The first ray originates from the bottom:

Code Snippet:

<div id="firework"></div>

Styling:

#firework {
  background-color: red;
  border-radius: 30%;
  height: 0px;
  margin: 0px 0px;
  width: 2px;
  -webkit-animation: firework-0 1s 1;
}


@-webkit-keyframes firework-0 {
  0% {
    height: 0px;
    margin-top: 0px;
  }
  50% {
    height: 64px;
    margin-top: 0px;
  }
  100% {
    height: 0px;
    margin-top: 64px;
  }
}

Fiddle Sample: http://jsfiddle.net/xcWge/1407/

Does anyone know how to replicate this effect every 36 degrees? I attempted creating a ray from the top, but using the margin attribute for the same head/tail effect seems challenging. While researching circular placements (Position icons into circle), I couldn't figure out how to maintain the radial animation effect. Any ideas?

Answer №1

Creating a Firework Effect:

If you're looking to create a firework effect using CSS, it can be quite challenging with just one element. To achieve this, you'd need multiple elements representing the spokes of the firework. Positioning them absolutely and rotating them by specific angles will give the desired effect. The animation can then be accomplished using linear gradients and adjusting their positions.

Here's an example of how you can create a basic firework effect using CSS:

.firework {
  position: absolute;
  top: 100px;
  left: 100px;
  border-radius: 30%;
  height: 64px;
  width: 2px;
  background: linear-gradient(to top, red, red);
  background-repeat: no-repeat;
  background-size: 100% 64px;
  background-position: 0px -64px;
  transform-origin: bottom;
  animation: firework-0 1s 1;
}
.firework:nth-child(2){
  transform: rotate(36deg)
}
/* More 'firework' classes for rotation angles */
@keyframes firework-0 {
  0% {
    background-position: 0px 64px;
  }
  50% {
    background-position: 0px 0px;
  }
  100% {
    background-position: 0px -64px;
  }
}

Note that reducing the number of elements by using pseudo-elements is also possible but requires some tweaking.


Advanced Firework Effect with CSS:

If you want your firework lines to appear separate yet arranged in a circle formation, a more complex animation is needed. By incorporating transparency in a gradient and animating the background size and position, you can achieve this effect.

Check out the following CSS code snippet for a more detailed firework animation:

.firework {
  position: absolute;
  top: 100px;
  left: 100px;
  border-radius: 30%;
  height: 64px;
  width: 2px;
  background: linear-gradient(to top, transparent 32px, red 32px);
  background-repeat: no-repeat;
  background-size: 100% 64px;
  background-position: 100% calc(100% - 32px);
  /* Animation properties */
}

Using the 'calc' function in background position ensures the correct positioning of the gradient for smooth animation.


Creating a Firework Effect Using SVG:

To achieve intricate firework effects, consider utilizing Scalable Vector Graphics (SVG). SVG provides a more precise toolset for such animations and is easier to maintain. Here's how you can use SVG for a firework effect:

The SVG code snippet below demonstrates how you can create visually appealing firework lines. Adjusting stroke dash attributes and animating them will give the desired explosive effect:

svg{
  width: 128px;
  height: 128px;
}
line{
  stroke: red;
  animation: firework 1s 1;
  stroke-dasharray: 32 32; 
  stroke-dashoffset: -32; 
}
@keyframes firework{
  from{
    stroke-dashoffset: 32;
  }
  to{
    stroke-dashoffset: -32;
  }
}

For different firework effects, adjust the line coordinates and stroke attributes accordingly within the SVG environment.

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

Having trouble with aligning middle of absolutely positioned block text vertically

I'm facing an issue with aligning h2 text vertically in the middle of a block. The situation is that I have multiple images with different heights but the same width (300px), each with varying amounts of text that may span over several lines and appe ...

Uncovering Inline Styles Infused with Javascript for Effective Debugging of Javascript Code

SITUATION: I have recently inherited a website from the previous developer who has scattered important functions across numerous lengthy JS files. I am struggling to track down the source of an inline CSS style within the JS or identify which function is d ...

Image displayed in tooltip when hovering over

I have been experimenting with displaying an image in a tooltip when hovering over it. I came across a fantastic solution that suits my needs: Codepen CSS: @import "compass"; * { box-sizing: border-box; } .tooltip { position: relative; border-bo ...

Tips for closing a modal in JavaScript after submitting the form

As I try to learn JavaScript, I'm creating my Quiz game and encountering an issue with a modal window. After entering my nickname and pushing Submit, I want to save the nickname in localStorage and close the modal window. However, the problem is that ...

Problem with CSS multi-level dropdown navigation in a vertical layout

I am in the process of creating a navigation menu with dropdown menus, which are working correctly. Now, I would like to add another sub-menu drop down inside dropdown 1, but I am having trouble getting it to function properly. How can I make Sub Menu 1 ac ...

Using Angular 2 to position a md-fab button with 'position: fixed' inside an inner component

Utilizing the md-fab-button from the initial angular2 material-framework has presented a challenge for me. I am attempting to set the md-fab-button(for adding a new entity) with position: fixed, but my goal is to position the button within an inner compone ...

The child fieldset is oversized with a height of 100%

I am attempting to make a fieldset child stretch to 100%, but the child (ul) is too large and causing overflow (getting cut off in my scenario). Is there a way to stretch the fieldset child to 100% without causing overflow? fieldset { height: 300px; ...

What is the best way to showcase a full-screen overlay directly inside an iFrame?

As I work in HTML, I'm faced with a challenge - my iFrame is only taking up a small section of the screen (referred to as 'World' in the example below). What I want to achieve is creating a full-screen div overlay from that iFrame, but curr ...

Creating space between flex items in Slick Carousel with Vue

This is my current Slick Carousel. There are 4 items in a row, and I am looking to insert some margin between each item while maintaining the existing aspect-ratio: 1.3/1; I'm struggling with overriding the classes from vue-slick-carousel. Does any ...

How can I fix the issue of the header background image not resizing properly? Any suggestions?

I am currently working on improving the responsiveness of my website when a user resizes their browser window. One specific issue I'm facing is resizing the banner image as the window size changes. The website in question can be found at The CSS code ...

CSS: Inaccurate positioning and border-radius causing gap between div and border-bottom

My goal was to create a card game with multicolored, double-sided borders, but I encountered issues when trying to implement this feature. Initially, I attempted to use an onclick event to change the border color, but it didn't work as expected. I fi ...

What is the reason a statically positioned element appears behind an absolutely positioned one?

I understand that absolute positioning disrupts the normal flow of elements, but I expected the display order to reflect the order in which elements are placed in the HTML code. .absolute { position: absolute; width: 100px; height: 100px; ...

Animating elements on a webpage can be achieved by using both

Is there a way to create an animation that moves objects based on button clicks? For example, when the "Monday" button is pressed, the object with the correct color will move down. If any other button like "Tuesday" is clicked, the previous object will mov ...

Boostrap: A guide to positioning a button on top of an image while resizing

Need help figuring out how to position and resize a button over an image on your website? Currently, the button is moving when you resize the browser window. You've tried using percentages in the CSS without success. What should you do next? <div ...

Loading CSS files in Next.js can sometimes require additional time for the styles to

Currently, I am working on a Next.js and Spring Boot project. However, I am facing issues with the loading of CSS files as they are taking a considerable amount of time to load. When I open a page, initially it appears without any styling, but after a few ...

Is it possible to sanitize user input without relying on !important?

Utilizing wp_editor, I have implemented a front-end form on my WordPress website for users to post without accessing the admin section. Although it is functional, there is a concern that users may copy and paste content with inline styles that could disrup ...

jQuery Mobile panel buttons are functioning properly within a maximum width of 300 pixels

I have constructed a panel that adjusts its size based on the device's screen using responsive design techniques. The code for this panel is as follows: <div data-role="panel" data-position="right" data-display="overlay" data-theme="a" id="add-for ...

Following the submission of a message, the textarea automatically inserts a line-break

Can someone please help me troubleshoot an issue with my chat app? Every time I try to send a message, the textarea adds a line break instead of just focusing on the textarea so I can send a new message smoothly. I have recorded a video demonstrating the ...

What is the method to restrict the coverage of the background color within a specific region in HTML?

I am still fairly new to html so I apologize if this is a very basic question for you. Here is the css file that is causing me trouble: .sidepanel-list{ margin-left: 10px; background-color:lightgray; Whenever I run the code, the background color s ...

Customizing Forms with Bootstrap Styling in HTML

Is there a way to rearrange this list so that the buttons appear above the textboxes, like in the desired formatting example The code is as follows: <form id="Data" runat="server" class="p-3 mb-2 bg-primary text-dark"> <div class="form-gr ...