CSS animations - Modifying a style element while maintaining the existing timing restrictions

I use CSS transitions to rotate an image

img {
    transition:all 5s ease-out;
}

To change the rotation direction, I utilize jQuery

$('img').css({'transform':'rotate('+2000+'deg)'});

Is it possible to switch the rotation direction randomly during the animation while maintaining the current easing and duration?

Answer №1

Did you give this a shot?

section {
  background: blue;
  width: 150px;
  height: 150px;
  transition: all 3s ease-in-out;
}

section.rotateClockwise {
  transform: rotate(180deg);
}

section.rotateCounterClockwise {
  transform: rotate(-180deg);
}

$('section').addClass('rotateClockwise');

setTimeout(function() {
  $('section').addClass('rotateCounterClockwise');
},3500);

https://jsfiddle.net/a1b2c3d4/

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

Storing the outcome of a query into a variable in Node-RED

I am facing an issue where I need to transfer the value of Object[0] nazwa, which is obtained from a query result (let's say "ab" in this scenario), to another variable. Since I am new to red node and JS, I'm unsure about how to accomplish this t ...

Troubles with setting up node modules in a Windows 10 environment

I'm encountering difficulties when trying to install modules on my Windows 10 laptop after setting up Node.js from scratch. Since it's my personal computer, I have complete control over the system. Despite searching through various online forum ...

Encountering the error message "Endpoint /api/Questions/ not found - 404"

Having recently delved into the world of Asp.net and Javascript, I find myself stuck on what to input in the 'url' to retrieve data from my controller that accesses an entity framework database. Despite multiple attempts, I keep encountering the ...

Auto-fill feature malfunctioning

Currently, I have implemented jQuery Autocomplete to retrieve data from a database and display it in the search box. Everything is working perfectly fine, except for one issue - when hovering over the results in the dropdown, instead of displaying the resu ...

Retrieve an item from a mapped array

Currently, I am using the following code snippet console.log('errors: ' + password.get('errors')); to check the output from password.get('errors'));, and in the console, the response is as follows: List [ Map { "id": "validat ...

Looping precisely five times in Vue3JS over an array and conditionally verifying each element within

After spending the past 2 hours searching through similar subjects on SO without success, I am turning to you for help. My goal is to create a scoreboard displaying results in the following format: John Doe 100 pts John Smith 50 pts No Name No Name No Na ...

What differences exist in the implications of the options for the socket.io server object?

According to the socket.io documentation, you have the option to utilize the http.Server object or directly input a port number into the socket.io server object. What distinguishes the two methods? Instantiate the socket.io Object const io = require(&apo ...

Tips for Showing Websocket Response On Web Browser Using Node.js

Just starting out with NodeJS and here's my code snippet: const webSocket= require('ws'); const express = require('express'); const app=express(); Var url = "wss://stream.binance.com:9443/BTCUSDT@trade`" const ws = new webS ...

jQuery-powered automatic horizontal scrolling

Does anyone know of a jQuery plugin that allows for scrolling of a div element when hovering over an arrow? The desired functionality is similar to the following image: , where the content inside automatically scrolls left or right when the user hovers ove ...

Find out if OpenAI's chat completion feature will trigger a function call or generate a message

In my NestJS application, I have integrated a chat feature that utilizes the openai createChatCompletion API to produce responses based on user input and send them back to the client in real-time. Now, with the introduction of function calls in the openai ...

AJAX jQuery requests can flatten arrays when they are sent

The below code shows an endpoint written in Express, using the body-parser middleware. app.post("/api/poll/new",api.NewPoll); api.NewPoll = function(req,res){ if(!req.body) return res.status(400).send("MISSING BODY"); console.log(req.body,typeof(r ...

Transmitting Data to PHP Using JQuery/AJAX

I'm struggling with this issue. Here is the HTML code that I have: <input type="text" class="studno"><input type="button" value="Check" class="chstudno"> How can I send this data to PHP using JQuery/AJAX? Below is the code that I current ...

What strategies can be employed to streamline the code provided?

Can someone help simplify this JavaScript code for me? I would really appreciate it. Thank you! $(function() { $("#show1").click(function() { $("#showmore1").toggle(); }) $("#show2").click(function() { $("#showmore2").toggle(); ...

Tips for properly formatting objects in a JSON file with commas using nodejs

I have a client-server setup where I am sending right click coordinates from the client side to the server side and storing them in a JSON file. Each coordinate is stored as a separate object in the JSON file. This is an example of how my JSON file looks: ...

Tips for properly indenting checkbox and radio button elements in HTML code

Check out my live code demo here This is a simple html code where I am attempting to indent radio buttons and checkboxes, but it's proving to be difficult. <tr> <td> <table> <tr& ...

The error message in Next.js states: "Attempting to access properties of undefined (specifically trying to access 'indexOf')."

After successfully running the code below, I encounter an issue upon refreshing the page: TypeError: Cannot read properties of undefined (reading 'indexOf'). const [folders, setFolders] = useState([]); const [user] = useAuthState(auth); c ...

Attempting to utilize CSS to address a persistent problem in Chrome where the page orientation options briefly appear when printing before being hidden

I am struggling to print a webpage in landscape orientation using the chrome browser, but I don't have control over the page's settings. You can see the issue discussed here: Chrome Print dialogue not offering fit to page, landscape, other prin ...

Click the button to save the text to your clipboard with a customized

Can anyone suggest a method for duplicating div text using JavaScript while preserving the style attributes (italics, font family, size, etc.)? My goal is to paste the copied text into Word and have it maintain the same appearance as on the webpage. For e ...

Issue with AJAX navigation and window.history.pushState: Inability to go back using the "back" browser button

I have developed a small Javascript tool to enable partial content loading in a Plone site using AJAX (the global AjaxNav object contains all the necessary functions). I want the browser history (back and forward buttons) to work correctly, so I wrote the ...

Using variable field names with jQuery's each function

I am working on dynamically passing a field name to my function so that my form can utilize autocomplete. When I call this function on my page, I encounter an error because it seems to be taking the column property literally instead of dynamically. In PHP ...