Rotating and spinning images with HTML/CSS while also adding an ease-out effect

After experimenting with numerous CSS snippets, I found that none fulfill all my requirements.

Here's what I'm aiming to achieve within the function myspin(x){}:

1.) Rotate image x degrees invisibly on click
2.) Then smoothly animate a spin of 800 degrees visible
3.) End with a slow ease out effect
4.) Reset all necessary properties for reusability upon the next button click

function myspin() {
  var x = 800;
  document.getElementById("arrowid2").style.transform = "rotate(" + x + "deg)";
  document.getElementById("arrowid2").style.animation = "arrowspin 2s ease-out 1 normal";
}
#arrowid2 {
  position: absolute;
  top: 100px;
  left: 100px;
  -webkit-transition: -webkit-transform 2s ease-out;
}
<body text="#000000" bgcolor="#FFFFFF" link="#FF0000" alink="#FF0000" vlink="#FF0000">
  <input type="button" value="click" onclick="myspin();" />
  <br/>
  <br/>
  <br/>
  <img id="arrowid2" src="arrow001.png" alt="" border="0" width="87" height="306">
</body>

Answer №1

All rotations are achieved using CSS, with JavaScript only adding/removing the animated class after 2500ms (the animation duration). What is the reason for wanting 800 degrees? If that is the case, it will cause a jump to the existing position. Currently, I have set it to rotate 360 degrees three times so the animation ends where it starts.

$('img').click(function() {
  $(this).addClass('animated');
  var that = this;
  setTimeout(function() {
    $(that).removeClass('animated');
  }, 2500)
});
img {
  width: 400px;
  height: 135px;
}
img.animated {
  animation: spin ease-out 2.5s;
}
@keyframes spin {
  0% {
    opacity: 0;
    transform: rotate(20deg);
  }
  10%{
    opacity: 0;
  }
  20% {
    opacity: 1;
  }
  100% {
    transform: rotate(1080deg);
  }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<img src='https://puu.sh/tTsnZ/9294a8c88e.png' />

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 function forEach is unable to handle the process of uploading multiple images to cloudinary

I'm facing an issue with uploading multiple images to Cloudinary from my Vue2JS front-end. I have successfully created a function that uploads a single image, but I am struggling with uploading multiple images using a forEach loop. upload(evt) { ...

Is it possible to automatically redirect to a different URL if the server is running slow when clicking?

Is it possible to utilize Javascript, AJAX, or another client-side technology to automatically redirect the user to a different URL if the initial URL is slow to respond when clicked on? For example, if a link redirects to URL1 and there is no response fr ...

Is there a way to attach event listeners to dynamically inserted elements within a Google Calendar interface?

This particular issue is closely related to a few other questions: Jquery adding event listeners to dynamically added elements Add Event Listener for dynamically created particular element using jquery If you want to see a working example, check out thi ...

Creating a resizable textarea component in JavaScript/React that adjusts its height dynamically but stops growing when

I am looking to create a textarea that initially displays as a single line but can expand up to 4 lines, and then start scrolling once the maximum height is reached. I have a solution in progress where it grows up to the limit, but does not shrink back dow ...

Unable to adjust the width of a label element using CSS specifically in Safari browsers

Here's the issue I'm facing with my HTML code <input type="checkbox" asset="AAA" name="assets[AAA]" value="AAA" id="assets[AAA]" class="c_green" checked="checked"> <label for="assets[AAA]"></label> In my CSS, I have the follow ...

What is the best way to encapsulate all request handlers within a wrapper function in an Express application?

While working on my express application, I came across the idea of creating a wrapper function to handle async request handler functions in a more efficient way. Instead of having a try-catch block for each handler, I wanted to streamline the process by cr ...

Updating the state within a component while specifically modifying the second item within a list

Currently in the process of constructing a battleShip game using React. Within my component, I have a state structured as follows: each coordinate is paired with a list containing two statuses - 'empty' indicating the absence of a ship ('bu ...

"I'm curious about how to reset a form in reactjs hooks after it has been submitted

Just dipped my toes into the world of hooks and I'm stumped on how to clear input fields post-submit. Tried form.reset() but it's not doing the trick. import { useForm } from "react-hook-form"; import.... export default function AddUse ...

Tips for extracting values from a JSON object in Angular when dealing with a JSON string

Storing column values as a json string in the DB table and then sending them to the front end as a json object. [ { "jobId":"efe0ace0-8ed9-45ff-9232-974cbdc89b86", "jobType":"TestExecutionJob", "nextRun":"N/A", "lastRun":"20 ...

The PhoneGap Android whitelist feature seems to be malfunctioning and preventing navigation to the next page

Currently, I am utilizing the jQuery function load() with the code snippet $('#result').load('http://.... #div'); to retrieve the content of an external website. Moreover, I have made modifications to the domain whitelist specifically f ...

Encountering a problem when using the routingService to navigate inside a JavaScript function

Within my Angular component, I have a method called onCellPrepared. In this method, I am using jQuery to attach a span tag. I want to be able to trigger an Angular service to navigate to another page when the span tag is clicked. How can I successful ...

Angular causes HTML Dropdown to vanish once a null value is assigned

In my scenario, I have two variables named power and mainPower. Both of these variables essentially represent the same concept, with mainPower storing an ID of type Long in the backend, while power contains all attributes of this data transfer object. The ...

Leveraging configuration files for HTML pages without any server-side code

I am currently working on developing an app using phonegap. At the moment, I have the reference to a script in every page like this: <script language="javascript" src="http://someServer/js/myscript.js"></script> If the server 'someServer ...

Retrieve the $ionicConfigProvider within a Controller

In my controller file named ProfileController.js, I am trying to change the text of the back button. After doing some research, I found this code snippet: $ionicConfigProvider.backButton.text('Go Back').icon('ion-chevron-left'); How can ...

Troubleshooting: Issues with jQuery's Class selector

Having trouble setting up an alert to trigger when a specific class anchor tag is clicked inside a div. This is what my HTML section looks like... <div id="foo"> <a class='bar' href='#'>Next</a> </div> And h ...

The TradingView advanced chart encountered an error while trying to read properties of undefined, specifically the 'startsWith' property

While integrating TradingView with Reactjs based on the step-by-step documentation provided by TradingView, I came across two errors in the console. The first error was: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'st ...

Grab the current URL using useRouter in a Next.js app

I am using userouter to obtain the URL of the current page and then utilizing the clipboard to copy it. However, I am encountering an issue where the copied content shows as object object instead of the expected URL. Can someone please help me identify w ...

Exporting modules in Node.js allows you to use functions

Can you explain why this code snippet is successful: exports.foo = 'foo'; var bar = require('./foo'); console.log(bar); // {foo: 'foo'} While this one fails to produce the desired output: var data = { foo: 'foo' ...

Discovering the most recent Node.js version: A step-by-step guide

Is it possible to check the latest available Nodejs version using npm? While node -v allows us to see the current version, I am curious if there is a way to access the most recent version through JavaScript. For example, process.version can be used to vi ...

Can someone guide me on how to incorporate page transitions into my website design?

Being a new PHP developer with experience in HTML, CSS, and JQuery, I am unsure how to implement page transitions. After finding an impressive example, I would appreciate some guidance. Example:This site showcases the page transitions I want to replicate. ...