Trigger the animation to run at regular intervals with an initial delay before starting and running on every iteration

I am trying to make an HTML button spin in a specific pattern. The button should start spinning after 5 seconds, then rotate for 2 seconds, stop for 5 seconds, and repeat this pattern indefinitely. I have searched for solutions but haven't found one that fits my requirements. Here is the code I currently have, with a rotation speed of 400ms:

 #register_event{
   animation: wiggle 400ms infinite;
 }

 @keyframes wiggle{
   0%{
     transform: rotateZ(0);
   }

   50%{
     transform: rotateZ(-10deg);
   }

   100%{
     transform: rotateZ(10deg);
  }
 

Answer №1

If you want to keep an animation running continuously in CSS, you can use the 'Infinite' keyword. To achieve this effect in your code, simply modify it as follows:

#register_event{
   animation: wiggle 400ms 3s infinite ease-out none;
 }

@keyframes wiggle{
   0%{
     transform: rotateZ(0);
   }

   50%{
     transform: rotateZ(-10deg);
   }

   100%{
     transform: rotateZ(10deg);
  }
 }

To ensure compatibility with various browsers, make sure to test different placements of the 'infinite' keyword within the shorthand property 'animation'. This should guarantee a flawless functioning of the animation.

Answer №2

To create a delay between two runs, add a keyframe that does nothing (like the 60% one in my example). This way, the following 40% won't have any changes compared to the initial 0%.

@keyframes wiggle{
    0%{
        transform: rotateZ(0);
    }
    
    25%{
        transform: rotateZ(-10deg);
    }
    
    50%{
        transform: rotateZ(10deg);
    }
    60%{
        transform: rotateZ(0deg);
    }
}


#register_event{
    animation: wiggle 2s infinite;
    animation-delay: 2s;
}

Use the animation-delay property for the initial delay and set it to run infinitely. Adjust the keyframe percentages and overall duration of the animation to get the desired timing. It just requires a bit of math, but I'm confident you can understand the technique!

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 impact of CSS padding on the dimensions of a component

Is there a way to maintain the fixed width and height of a button or label even after adding padding? I attempted to use box-sizing:content-box, but it didn't work as expected. View the example code here Thank you in advance. ...

Changing the color of text in one div by hovering over a child div will not affect the

When hovering over the child div with class .box-container, the color of another child div with class .carousel-buttons does not change. .carousel-slide { position: relative; width: inherit; .carousel-buttons { position: absolute; z-index: ...

Determine the aspect ratio with a constant adjustment using CSS/SCSS

I am trying to adjust the aspect ratio of a responsive div to create a square shape with an offset. I want the height to be equal to the width plus the specified offset. Here is an example of what I am attempting: .div { width: 100%; aspect-ratio: 1 / ...

Are there any real-world examples you can share of utilizing CSS 3D Transforms?

Can you provide any instances of CSS 3D Transforms being utilized in real-world projects besides and ? ...

What is the best way to apply a CSS class to a ComponentRef that has been generated in Angular 5

I am attempting to dynamically add a CSS class to a component right after its creation by utilizing ViewContainerRef and ComponentFactoryResolver. My goal is to determine the class based on which other Components have already been added to myViewContainerR ...

Replacing text in the main navigation bar with sIFR

Could this menu layout be improved? <div class="navigation"> <ul id="nav-menu"> <li class="active"> <div class="sifr-r active"><a href="#" title="home" class="top-link"><span class="blue-small">01.</span& ...

Navigating on the horizontal axis within a container with overflow properties

I am trying to insert multiple children-divs into a parent-div. The parent div has a fixed width. The children are set to float left and will overflow the container. I need the ability to scroll along the x-axis. However, when I attempt to do this, the c ...

The JavaScript-rendered HTML button is unresponsive

I have a JavaScript function that controls the display of a popup window based on its visibility. The function used to work perfectly, with the close button effectively hiding the window when clicked. However, after making some changes to the code, the clo ...

Use JQuery to constantly monitor for any changes in HTML Div

I am dealing with a browser-based chat application where separate div elements are generated for each chat conversation. An external module oversees the entire chat process, and I do not have access to its underlying code. It is important to note that the ...

How come the position sticky content vanishes when a z-index is applied?

Can someone assist with the issue I'm having regarding the use of sticky and z-index? Whenever I apply a z-index to a positioned sticky element, its content disappears. Question: How can I utilize z-index for a positioned sticky element without any c ...

Customizing Bootstrap css variables for a unique design

Currently, I'm working on tweaking the data-bs-theme in Bootstrap 5.3. My goal is to adjust the pre-defined CSS variables of the Bootstrap dark theme and refresh the color palette. Specifically, I want to change the shade of blue for my blue button (b ...

Height and Width Dilemma in Visuals

Can you help with changing image resolution using jQuery? I have a background image applied to the body using CSS/PHP. My goal is to make the image fill the entire window by applying the screen height and width, without using repeat style. The code I am c ...

Header text aligned with image to accommodate parent size

Having trouble aligning an image/logo next to my header text while maintaining its aspect ratio and fitting within the container size. The goal is to have both the text and image horizontally centered. The parent div cannot have a fixed height as it needs ...

Positioning Tumblr blockquotes beneath each other, rather than within

Just diving into the world of HTML/CSS and I've been working hard on creating my own Tumblr theme (almost finished!). One issue I'm having is styling the replies, which are in blockquote form. I want them to display one after another in a line li ...

A difference in the way content is displayed on Firefox compared to Chrome, Edge, and Safari

Recently, I encountered an issue with a tool I had developed for generating printable images for Cross-Stitch work. The tool was originally designed to work on Firefox but is now only functioning properly on that browser. The problem at hand is whether th ...

Implementing a feature that ensures html elements are transparent in a PDF conversion

I am in the process of converting a webpage into a format that is easily printable as a PDF, while ensuring that it maintains the same appearance. Many tools for printing to PDF do not support background images or colors, so I am attempting to overcome thi ...

A fading transparency box on the border

Looking for a box with varying opacity from left to right (See image for reference - the red marked box has decreasing opacity from right to left). Here is my attempt: .waterMark { background-color: #FFFFFF; float: right; opacity: 0.6; position: ...

Guide to dynamically adding two CSS files in a single component in Angular 8

Within this component, there is a form that needs to support two languages, each with its own unique CSS style - one for left-to-right (ltr) direction, and the other for right-to-left (rtl) direction. Is there a way to conditionally apply two different CS ...

Animate images using mouse vertical movement

Creating websites is just a hobby for me, not something professional. Recently, I came across a beautifully designed website that had some unique features I hadn't seen before, like placing three images in one div (which I researched and learned how t ...

unitary incline division assemblage

I noticed a particular element in the design that is currently displayed with an image (png). However, I am facing limitations due to needing to make it adaptive. Can a gradient be used as a sub-element instead? background-image: linear-gradient(to left, ...