The swinging motion of my reboot sign is perplexing, but the solution lies in simply approaching it directly. How can I address this issue effectively?

I've been struggling with a reloading issue that keeps going back and forth when all I need is for it to go back. I've tried everything I know, but nothing seems to work. Any help would be greatly appreciated. Thank you in advance :)

var reload_button = document.getElementById("reload");

document.getElementById("btn").onclick = function () {
  if (reload_button.style.transform == "rotate(360deg)")
    reload_button.style.transform = "rotate(0deg)";
  else reload_button.style.transform = "rotate(360deg)";
};
#reload {
  display: block;
  margin-left: 100px;
  position: absolute;
  font-size: 40px;
  transition: 2.5s;
}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script
      src="https://kit.fontawesome.com/8f82e7a054.js"
      crossorigin="anonymous"
    ></script>
    <link rel="stylesheet" href="main.css" />
  </head>
  <body>
    <div id="reload"><i class="fas fa-redo"></i></div>

    <button id="btn">CLICK ME</button>

    <script src="main.js"></script>
  </body>
</html>

Answer №1

To incorporate animation into your design, you can utilize a method that involves adding and removing a specific class at the beginning and end of the animation:

var reloadIcon = document.getElementById("reload");

reloadIcon.addEventListener("animationend", function() {
  reloadIcon.classList.remove('rotate');
});

document.getElementById("btn").onclick = function() {
  reloadIcon.classList.add('rotate');
};
#reload {
  display: block;
  margin-left: 100px;
  position: absolute;
  font-size: 40px;
}

.rotate {
  animation: spin 2s;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
}
<script src="https://example.com/script.js" type="text/javascript"></script>

<div id="reload"><i class="fas fa-refresh"></i></div>

<button id="btn">CLICK HERE</button>

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

Receiving HTTP POST data using Classic ASP script

I'm currently working on a project and have come across an area where I am facing some challenges. Despite my best efforts, I haven't been able to find a solution using Google. In my ASP web application, I've added an HTML canvas that I nee ...

Numerous inline notations in html code

I need help figuring out how to prevent a hyperlink from opening a new tab by commenting out the HTML code. <a href="<!--http://www.google.com=-->" target="_blank" onclick="javascript:alert('Navigation Prevented')">CLICK HERE FOR GOO ...

Navigation bar with a full-page slider

I am trying to incorporate my bootstrap nav bar into a full-width slider, similar to the layout in this example. https://i.sstatic.net/LE9wP.jpg This is the full width slider http://codepen.io/grovesdm/pen/MazqzQ Currently, I have positioned the nav ba ...

I'm having trouble with my dropdown navigation menus - they keep popping back up and I can't seem to access

My website is currently in development and can be accessed at: The top navigation bar on the homepage functions properly across all browsers. However, there are three sections with dropdown submenus - About Us, Training, and Careers. These dropdown submen ...

Is there a method in Angular to refresh or recompile a specific section or entire page that utilizes one-time bindings?

With numerous lists on our page containing potentially hundreds of items, we prioritize performance by implementing one-time bindings to update only when necessary and minimize the number of watchers. If we decide to utilize one-time bindings, is there a ...

Is there a way to have multiple app.post functions for the same route using express()?

I'm currently exploring the idea of incorporating multiple app.post functions in my project. Specifically, I have a client-side JavaScript function that sends a request to the server-side JavaScript to add content to a database using the app.post func ...

How to utilize local functions within a ko.computed expression

Why isn't this line of code working? I'm using durandal/knockout and my structure is like this define(function () { var vm = function() { compute: ko.computed(function() { return _compute(1); // encountering errors }); ...

Arranging Pictures Beside Text Using CSS

I have a puzzling issue that I cannot seem to find an answer for despite the countless times it has been asked. In my footer, there is aligned copyright text, and I am attempting to add 3 logos to the right of it without any line breaks. However, when the ...

Caution: Additional server attributes detected: style

Alert in my Next.js project, I encountered the following message: Notice: Server is sending additional attributes: style I am uncertain about the source of this warning and therefore unable to provide any code snippet. ...

Tips for preserving my cookies and URLs in a text file

I'm facing an issue with logging my Cookies and URL. I am able to log them, but I am struggling to set them to variables. Can someone please assist me with this? When I try to set both of them to variables, all I get in return is Promise { } driver ...

Incorporating an external JavaScript or CSS file into a Java web application at runtime

I am looking to dynamically add an external JavaScript or CSS file in my test.html file. Although I am aware of a trick that involves using jQuery like this: $(”).appendTo(‘head’).attr({ rel: ‘stylesheet’, type: ‘text/css’, href: ‘**ht ...

Connecting a CSS file with an HTML document

Having an issue with my CSS. For instance, here is a snippet from my CSS file .readmore { font-style: italic; text-decoration: none; color: #509743; padding-left: 15px; background: url(../images/more.png) no-repeat 0 50%; } .readmore: ...

'Error: The type is missing the 'previous' property - Combining TypeScript with ReactJS'

I am quite new to using reactjs and ts. While I understand the error that is occurring, I am unsure of the best solution to fix it. Currently working with reactjs, I have created an: interface interface IPropertyTax { annul: { current: number; p ...

Creating One to Many Table Joins with Knex.js

My current situation involves working with two tables: In the quotes table, we have columns such as first_name, email, estimate, and more. Then, there's the quote_notes table with columns like id, note, and quote_id. The relationship between these ...

Transition from the previous image to the new one with a fading effect to enhance list item navigation

I've been working on implementing a sprite image for each list item (home, services, and contact) in my project. Using CSS, I've managed to move the position on hover successfully. However, I now want to add a fade effect to the transition instea ...

Customizing React-Data-Grid styles using Material-UI in a React application

Imagine a scenario where we have a file containing themes: themes.js: import {createMuiTheme} from "@material-ui/core/styles"; export const myTheme = createMuiTheme({ palette: { text: { color: "#545F66", }, }, }); In ...

"Exploring the benefits of using nested mapping for res.json() in an Express application

I have been developing an express application (server-side) that offers movie information to users, and I am attempting to send a JSON response in the following format: { "title": "Star Trek: First Contact", "year": 1996, ...

Tips for avoiding duplicate checkboxes in AngularJS when labels are the same

In the code snippet above, there is an issue with the repeating checkboxes. The code generates checkboxes based on the data provided to filter a table, but sometimes it results in multiple checkboxes with the same label '123'. How can I modify th ...

How can you implement a delete button in jQuery DataTables using an API?

Is there a way to incorporate the delete button using the jQuery DataTables API? I have successfully installed the DataTable but am facing challenges in implementing the necessary methods. Any assistance would be greatly appreciated. Thank you! Visit thi ...

Ways to create adaptive images using Bootstrap 5

On my website, there are some cards that look great on large and medium screens. However, on small screens, the images appear stretched vertically! I am using Bootstrap 5 and here is the code snippet: <div class="col-12 mb- ...