Create a distinct CSS animation 'origin' declaration for every <g> element

I am using CSS animation to apply a 'wobble' effect to each letter within a word. The letters are represented by SVG groups <g>. However, in the provided example, the wobbling effect becomes more pronounced with each subsequent letter, whereas I desire a consistent 'wobble' for each individual letter. How can I achieve this consistency?

Kindly note that I have omitted the SVG source code for the sake of clarity in the question. Should you require it, you can find it in the provided example.

Thank you.

SCSS

// Logo
.logo {
    position: fixed;
    top: 50%;
    left: 50%;
  transform: translate(-50%,-50%);
    z-index: 1;
    width: 260px;
    display: block;

    // SVG
    svg {
        display: block;
        width: 100%;
        overflow: visible;

        g {
            fill: transparent;
            transition: all 300ms ease-in-out;

            @keyframes wobble {
              0% { transform: rotate(0) translate3d(0, 0, 0) }
              25% { transform: rotate(2deg) translate3d(1px, 0, 0) }
              50% { transform: rotate(-1deg) translate3d(0, -1px, 0) }
              75% { transform: rotate(1deg) translate3d(-1px, 0, 0) }
              100% { transform: rotate(-2deg) translate3d(-1px, -1px, 0) }
            }

            animation-duration: 400ms;
            animation-iteration-count: infinite;
            animation-fill-mode: none;
            animation-name: wobble;
            animation-timing-function: ease-in-out;

            path {
                fill: red;
            }
        }
  }
}

Check out an Example here

Answer №1

Using SVGs seemed a bit tricky for me, but I did find a solution that resembles what you were looking for.

To achieve this, I had to make use of a central point for the rotation:

transform-origin: center;

Check out the demo below

#my-logo div {
  display: inline-block;
  color: red;
  font-size: 60px;
  font-family: arial;
  font-weight: bolder;
  text-transform: uppercase;
  fill: transparent;
  transition: all 300ms ease-in-out;
  transform-origin: center;
  animation-duration: 400ms;
  animation-iteration-count: infinite;
  animation-fill-mode: none;
  animation-name: wobble;
  animation-timing-function: ease-in-out;
}

@keyframes wobble {
  0% {
    transform: rotate(0) translate3d(0, 0, 0);
  }
  25% {
    transform: rotate(2deg) translate3d(1px, 0, 0);
  }
  50% {
    transform: rotate(-1deg) translate3d(0, -1px, 0);
  }
  75% {
    transform: rotate(1deg) translate3d(-1px, 0, 0);
  }
  100% {
    transform: rotate(-2deg) translate3d(-1px, -1px, 0);
  }
}
<div id="my-logo">
  <div>o</div>
  <div>u</div>
  <div>t</div>
  <div>r</div>
  <div>a</div>
  <div>g</div>
  <div>e</div>
  <div>
    <!-- also works with images -->
    <img src="http://placekitten.com/100/100" />
  </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

Ways to show text on top of an image using CSS

Seeking help! I'm attempting to overlay some text on top of an image, here's the link: http://jsfiddle.net/5AUMA/31/ The challenge is aligning this text to the bottom part of the image. I've tried using this CSS: .head_img p { position ...

Optimizing loading times for mobile banners through media queries

I currently have a standard size banner that loads when my page is accessed on a computer. However, I would like to optimize the loading speed by having a smaller version specifically for mobile devices using a media query. My main question is how does t ...

Revisiting the Issue: Jquery Hover Effect Fails to Function in Internet Explorer

Can anyone provide assistance with this issue? The code snippet works perfectly in all browsers except for IE, where the menu does not fade in and looks unattractive. html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.o ...

Is there a way to conceal the scrollbar while still permitting scrolling?

I'm interested in creating a custom scrollbar, but in order to do so I need to hide the default scrollbar while still allowing scrolling functionality. I've attempted: overflow-y:hidden; but this method hides the scrollbar and prevents scrolli ...

Unable to insert a new module position within the vertex joomla framework

I have successfully added a new module position to the right side of the menu in Joomla 3 using the S5 Vertex framework. The changes were made in index.php as follows: <div id = "s5_newmodule"> <?php s5_module_call('s5_newmodul ...

Is there a way to keep a div element anchored at the top of the page until I reach the bottom and then have it stick to the bottom as I continue

I have a question that I hope is clear enough! On my webpage, there is a div at the top that I want to move to the bottom when I scroll and reach the end of the page. Hopefully, you understand what I'm trying to achieve! If anyone has any ideas, I&ap ...

What is the best way to close all other accordion tabs when selecting one?

A simple HTML code was created with the full pen accessible here. <div class="center"> <div class="menu"> <div class="item"> <button class="accordionBtn"><i class=&q ...

What is the best way to display multiple HTML files using node.js?

click here to see the image Here is my server.js file. Using express, I have successfully rendered the list.html and css files on my server. However, I am encountering an issue when trying to navigate from list.html to other html files by entering localho ...

Flex items are overflowing, rather than adjusting their size

Here .header { display: flex; font-family: monospace; background: papayawhip; align-items: center; justify-content: space-between; margin-left: auto; } ul { display: flex; background: papayawhip; gap: 10em; list-style-type: none; f ...

Creating a responsive layout that sets the window height to 100% and automatically adjusts sibling divs when the content within parent divs exceeds the defined height

<section> <div class="section-wrap"> <h1>page1</h1> </div> </section> <section> <div class="section-wrap"> <h1>page2</h1> </div> </section> My attempt at impleme ...

The hamburger menu appears to be missing when viewing in Safari, while it functions properly on both Chrome and Firefox browsers

My website has a responsive menu that functions perfectly in Chrome and Firefox, but encounters issues in Safari on mobile devices. The site is built using Elementor WordPress and I believe adding some -webkit- properties could solve the problem, but I&apo ...

Complications arising from IE when using strict doctype with CSS and jQuery

Here's the code I'm using for a sliding caption effect on my gallery site: I specifically implemented the last effect which is the Caption Sliding (Partially Hidden to Visible). $('.boxgrid.caption').hover(function(){ $(".cover", th ...

Arranging divs with CSS positioning

I struggle with positioning divs, especially in this particular situation. I am attempting to position boxes in the following layout: _ ___ _ |_|| ||_| _ | | |_||___| Is there a way to avoid manually defining pixel positions for each box and ins ...

Using Tailwind CSS's width property w-11/12 actually returns a full 100% width instead of the expected 91.66

It seems that the w-11/12 class is not behaving as expected. According to the documentation, it should give a width of 91.666% but instead, it's filling up 100%. This issue only occurs with the value 11, while other values work fine. Has anyone else e ...

Whenever I create the code using javascript, padding seems to always show up

I have a basic stacked row layout that displays an upper box and lower box without any padding. <span id="route" class="small"> <div class="row" style="border-style:solid;"> <div class="col-md-12 col-12"> <p>UpperBox</p& ...

What is the best way to add a textfield within an image?

Does anyone have a code snippet that can generate a "search box" like the one on www.dx.com? I was shocked to find that searching for "textfield inside image" only yielded results for "image inside textfield". ...

Most left-aligned icon on the left, most right-aligned icon on the right, and evenly spaced icons in between

Imagine a scenario where you are presented with a questionnaire that allows you to respond using a slider (HTML range element). Below the div containing the range selector (slider), I have arranged icons that need spacing. The icon on the far left should ...

From Blender to Three.js: Creating Realistic Human Models

I am currently working on integrating an animated 3D character into a web browser. My process involves using MakeHuman 1.02 to create the character, which I then import into Blender 2.74 in .mhx format. I utilize the MakeWalk plugin for Blender to retarge ...

Enhancing WordPress Accessibility with Google Tag Manager

I have been utilizing the Google Tag Manager for WordPress plugin on my WordPress website. I have come across some important issues concerning compliance with the WCAG 2.0 accessibility guidelines. It has been brought to my attention that the Google Tag ...

Utilize import and export statements to transfer an HTML tag between two JavaScript files

I have two HTML files linked to two JS files. I want to save an HTML tag from HTML1 with JS1 in a Variable and export it. Then import it in the JS2 file and use it in HTML2 I have tried many ways but nothing seems to work, something as simple as this Exp ...