Steps to create a shake animation effect for a <span> element within a <div>

 <div id="about-desc">
    <p>
 Lorem dolor amet, consectetur adipisicing elit.  Officia reprehenderit, sit eligendi deserunt, blanditiis quas porro omnis provident quidem voluptate! Fugit ipsa mollitia, atque commodi asperiores, rerum dicta ratione aut.
    </p>
 </div>

$(document).ready(function () { 
  $(".animation").addClass("animated shake");
});

I am facing an issue and unable to pinpoint the root cause. The animation added to the div element is working correctly but not with the span element. Any advice on how to troubleshoot this problem would be greatly appreciated.

Answer №1

When it comes to transforming elements, remember that span is an inline element by default and cannot perform a transformation on its own. To enable transformation, you can either add display: inline-block to your animation or apply it directly to the span element.

Understanding Transformable Elements

A transformable element falls into one of these categories:

- An element whose layout is determined by the CSS box model, such as block-level or atomic inline-level elements.

- An element in the SVG namespace that does not follow the CSS box model but has attributes like transform, patternTransform, or gradientTransform.

For more information, refer to: https://drafts.csswg.org/css-transforms-1/#terminology

<span> in HTML serves as a generic inline container for phrasing content without any inherent meaning. It can be useful for styling purposes (using classes or ids) or when sharing attribute values like lang. However, it should only be used when no other semantic element is suitable. Remember, although similar to <div>, <span> is an inline element unlike <div>, which is a block-level element.

Learn more at: https://developer.mozilla.org/en/docs/Web/HTML/Element/span

Option 1: Add Shake Effect on Hover

$(document).ready(function () { 
  $(".animation").addClass("animated shake");
});
.shake:hover {
  animation: shake 0.82s cubic-bezier(.36, .07, .19, .97) both;
  transform: translate3d(0, 0, 0);
  backface-visibility: hidden;
  perspective: 1000px;
  display: inline-block;
}

@keyframes shake {
  10%, 90% {
    transform: translate3d(-1px, 0, 0);
  }
  20%, 80% {
    transform: translate3d(2px, 0, 0);
  }
  30%, 50%, 70% {
    transform: translate3d(-4px, 0, 0);
  }
  40%, 60% {
    transform: translate3d(4px, 0, 0);
  }
}

Option 2: Continuous Shake Animation

$(document).ready(function () { 
  $(".animation").addClass("animated shake");
});
.shake {
  animation: shake 0.82s cubic-bezier(.36, .07, .19, .97) both infinite;
  transform: translate3d(0, 0, 0);
  backface-visibility: hidden;
  perspective: 1000px;
  display: inline-block;
}

@keyframes shake {
  10%, 90% {
    transform: translate3d(-1px, 0, 0);
  }
  20%, 80% {
    transform: translate3d(2px, 0, 0);
  }
  30%, 50%, 70% {
    transform: translate3d(-4px, 0, 0);
  }
  40%, 60% {
    transform: translate3d(4px, 0, 0);
  }
}

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

What is the best way to ensure that cleanup is always executed at the conclusion of a function

Imagine a scenario where I have the following function (psuedo-code) : function Foo() { let varThatNeedsCleanup = //something if(condition1) { return Error1; } if(condition2) { return Error2; } if(condition3) { return Error3; ...

Reveal the administrator's details exclusively when the associated radio button is chosen

Managing administrators for a post can be done through an editing page with corresponding radio buttons. Each radio button is linked to a different administrator, and selecting one populates the form fields with that admin's details. The issue arises ...

JavaFX WebView showcases HTML content differently compared to Libre Office Writer

After using SceneBuilder 2 to create a Dialog for displaying Help documents in a WebView, I proceeded to generate an HTML document in Libre Office Writer. Upon loading the 'Help.html' file, I noticed that the line spacing in the WebView differed ...

Updating an HTML Table with AJAX Technology

I'm struggling to figure out how to refresh an HTML table using AJAX. Since I'm not the website developer, I don't have access to the server-side information. I've been unable to find a way to reload the table on this specific page: I ...

Sending a POST request from AngularJS to the SLIM Framework appears to be causing issues

Greetings! I am facing an issue with my AngularJS http.post() request to the Slim PHP framework. 'use strict'; soup.factory('loginService',function($http){ return { login:function(user){ console ...

Troubleshooting Vue.js nested v-for with <tr> tag problem

Why does Vue complain about undefined properties when I try nesting a <tr> inside a <tr> with a v-for binding on each? <table> <thead></thead> <tbody> <tr v-for="item in items"> <td>{{ item.nam ...

Organizing menu options into subcategories using jQuery UI for easy sorting

I am currently working on a horizontal jQuery menu item that includes the sortable option and has one submenu. My goals for this project are as follows: To keep the menu item with the submenu locked at the end of the list To be able to drag menu items fr ...

Eliminate repeated elements by comparing two sets of data

I have two arrays of data, rlT and refundT. My goal is to eliminate any duplicate items from the rlT array that have a matching transactionId in the refundT array. I came across a solution using filter() and find() on Stack Overflow: Remove all elements co ...

Proper method of defining an action in Vuex

Do you think it's sufficient to create vuex-actions as simple as a1, without chaining then/catch calls? Or should I always go with creating Promises as in a2 (and also adding a reject branch)? Appreciate your insights... import Vue from 'vue& ...

What is the best way to iterate through my array of objects using a forEach loop and assign a value to the property of any object that has an empty string?

Inquiry for Part 1: I am currently exploring the use of forEach loop to iterate through an array of objects. My goal is to update the property "profile_image_url" of objects that have an empty string as its value, setting it to a default link ("/media/arti ...

I am unable to load any HTML files in my VueJS iframe, except for the index.html located in the public

Within the template of my vue component, I am utilizing the following code: <iframe width="1000vw" height="600vh" src="../../public/myHtmlFile.html"></iframe> Unfortunately, the file specified in the src attribut ...

Tips for managing various potential return types in TypeScript?

In my research on the topic, I came across a discussion thread about obtaining the local IP address in Node.js at Get local IP address in Node.js. In that thread, there is a code snippet that I would like to incorporate: import net from 'net'; c ...

The alignment of elements in the div seems to be slightly skewed

Currently, I am in the process of creating a website with the temporary name yeet.io. I am facing an issue where I am attempting to center both an input and h1 element inside a div vertically and horizontally, but they keep appearing misaligned for some r ...

It appears that the .fadeOut() function is not working properly when applied to an image

I want my input text box to automatically submit the form and display a checkmark image after the user has been idle from typing. I tried implementing a fadeout function for the image but it doesn't seem to be working. var timer = null; $('.form ...

What is the point of the horizontal scroll bar in WP Thesis?

There seems to be a horizontal scroll bar appearing at the bottom of my site, even though there is no content extending beyond the visible area. Can anyone provide guidance on how to fix this issue? My website is built on Wordpress 3.0 and utilizes the Th ...

AngularJS scope values fail to update within a jQuery promise/deferred context

I am currently working on a single page application using AngularJS. I have set up a controller with a function that executes upon clicking a button. This function involves a promise, and upon resolution, it should update a root variable and change the $lo ...

CSS not working when attempting to override Angular (13) Material file

In my Angular (13) application with Material, I have developed a CSS file specifically for overriding certain Material styles. This CSS file is imported into the styles.scss file as the last line. However, despite importing the external file, the CSS def ...

Automating the process of submitting a checkbox

Displayed below is a mix of HTML and JavaScript: <form method = "post" style="display: inline;" name="thisform<?php echo $employee->id; ?>"> <input type="hidden" name="user" value="<?php echo $employee->id; ?&g ...

How to Ensure Center Column Maintains Visibility on Mobile Devices with Bootstrap 4

Is there a way to ensure that page content stays centered without looking too narrow when viewed on mobile devices? Specifically, in the context of a single column layout that is centered. Although the current design appears well-balanced and spaced out o ...

What is the process for exporting MYSQL data within a specific date range using Laravel?

I have been struggling with a problem that might seem simple to some of you. I am able to filter out data based on a date range and display it in the view. However, I now need to export these searched/filtered results in CSV/Excel format. It would be incr ...