What would be the JavaScript version of the below jQuery code?

I am interested in creating a spinning wheel where instead of the entire wheel rotating, only the pointer rotates. I currently have a jQuery code snippet that achieves this effect, but I am looking to convert it into JavaScript.

Current jQuery code:

$( document ).ready(function() {
  var startJP = (164) + (360 * 3);
  $('.jackpot-pointer').animate({  transform: startJP }, {
      step: function(now,fx) {
        $(this).css('-webkit-transform','rotate('+now+'deg)'); 
      },
      duration:6000
  },'linear');
});

My goal is to achieve an effect similar to the one shown here: https://i.sstatic.net/0KArr.gif

Answer №1

Here is an easy demonstration of how you can achieve this using vanilla JavaScript and CSS with the help of CSS animations controlled by JS.

var stage = document.querySelector('#stage');
var rot = document.querySelector('#rotating');

stage.addEventListener('click', function () {
 rot.classList.toggle('animated');
});
#stage {
  position: relative;
  height: 100px;
  background-color: #000;
}

#rotating {
  position: absolute;
  top: calc(50% - 25px);
  left: calc(50% - 25px);
  width: 50px;
  height: 50px;
  background-color: #c00;
  animation: rotate linear 6s;
  animation-iteration-count: infinite;
  animation-play-state: paused;
  transform-origin: 50% 50%;
}

#rotating.animated {
  animation-play-state: running;
}

@keyframes rotate {
  0% {
    transform:  rotate(0deg) ;
  }
  100% {
    transform:  rotate(359deg) ;
  }
}
<div id="stage">
  <div id="rotating"></div>
</div>

You may need to add vendor prefixes in the CSS code depending on the browsers you want to support.

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

Alignment of inner div within the footer

I'm struggling to align my footer navigation inline with my footer title. Check out this code snippet to see what I've tried so far: https://jsfiddle.net/nkzsufov/ I experimented with using absolute and relative positioning: .footerNav { margi ...

Tips for resolving highlighted font awesome Facebook icon issue

Looking to create a circle around a fontawesome social media link. The circle works for most icons, but the Facebook icon is causing issues. The highlight circle does not fit correctly with the Facebook icon. How can this be resolved? .social-media span ...

The ripples can be found at the bottom of the map, not at the front

Having an issue when working with Globe where Ripple rings are always appearing on the backside of the map, rather than in front of it Referencing the source code from https://github.com/vasturiano/globe.gl/blob/master/example/random-rings/index.html and ...

Updating an array in JavaScript with a dynamically generated key name while working in the ReactJS framework

I have multiple dropdown menus, and when I select an option from any of them, I want to store the selected value in the component state. The onChange function that I call looks like this: function handleSelect(event) { console.log(event.target.value); ...

The functionality of WebDriver Wait is not functioning as expected

Is there a way to avoid waiting for the entire page to load? I thought using WebDriverWait would help, but I keep getting a TimeoutException even though the tag is visible. self.driver.get('http://www.quoka.de/') self.wait.until(EC.invisibility_ ...

How can you enable fullscreen for a featherlight iFrame?

I have implemented Featherlight to display an iframe within a popup modal on my website. If you click the iframe button, you can see a demo of how it works. One issue I am facing is that the generated iframe tag by Featherlight does not include allowfulls ...

Manipulate numerous documents within MongoDB by updating them with varying data in each

I have a list of unique IDs: idList = ["5ec42446347f396fc3d86a3d", "5ec422d4347f396fc3d86a3c", "5ecefaf0aead3070fbdab7dd"] I want to update the documents that match these IDs with different data in each one: const currentData = await Data.updateMany( ...

What is the best way to adjust column sizes, setting one with a minimum width while allowing the other to expand to accommodate its content?

In the process of creating a user interface, I have included clickable cards that reveal a detailed panel when clicked. The detail panel is set to a minimum width of 900px and should adjust to the remaining space between the cards and itself. The column ...

How can we generate 3 different arrays, each containing an equal number of items except for the last array, using VueJS?

Incorporating Bootstrap5 and VueJS 2, I am working on designing a layout of cards in a "pinterest-style" arrangement, as depicted in the following screenshot: https://i.sstatic.net/AvdWR.png To achieve the layout showcased above, the HTML markup required ...

Enclose chosen images with selection made

Below is the code snippet I am working with: <select multiple="multiple" class="image-picker show-html"> <option data-img-src="http://placehold.it/125x200" value="1">SportField 1</option> <option data-img-src="http://placehold ...

When the route is changed, the system must execute a function to verify the authenticity of the token

When routing changes in Angular, I have a requirement to execute a function based on whether a valid token is set or not. Is there anyone who can assist me in achieving this task? In Angular 1, I used to accomplish this using $on. ...

Apply a specific style conditionally using Angular's ng-repeat directive

Currently, I am utilizing ng-repeat to iterate through a list of divs and manually adding items to the JSON that is rendering these divs. My goal is to position the last div that I add in the JSON at the location where the mouse cursor is, while keeping th ...

The loading time for the Ajax request is unreasonably slow

I am currently managing a website dedicated to League of Legends. My main task involves requesting statistics from the Riot Games API based on a player's name, which returns the information in JSON format. However, there is a significant delay in load ...

Navigating through a predetermined list of HTML pages with next and previous options

Hey there, I'm in a bit of a quandary at the moment. I've been searching on Google for quite some time now, but unfortunately, I can't seem to find what I'm looking for. Hopefully, you guys can lend me a hand. What I'm trying to d ...

Passing a variable between two PHP files and then showcasing its value in a separate third file

bookincome.php receives several inputs, and bi.php calculates the total net income based on the values provided by bookincome.php. It then displays a table containing all the user-given values and the calculated total book income ($tnibeforetax) value. How ...

What could be causing the "undefined" property error in my Vue.js component?

In my Vue.js application, I have several components that are structured similarly and are all throwing the same error: TypeError: Cannot read property 'id' of undefined I initially attempted to resolve this issue by enclosing {{ jobs[0].id }} w ...

Having trouble with jQuery in Blogger?

I'm having trouble installing a Facebook slider tab on a friend's blog and I can't seem to get it to work. Here's the link to her blog: And here's the tutorial I'm following: jQuery is already installed on the blog (you can ...

The error message "TypeError: self.parent.parent.context.parseInt is not a function" indicates that

My goal is to set the height of an image using ngStyle by calculating it with a Math operation in the following way: <div [ngSwitch]="tbNm?tbNm:'itm0'"> <ion-list *ngFor="let vl of scrnshot;let ind=index"> <img *ngSwitch ...

What methods can I use to display or conceal certain content based on the user's location?

I'm looking to display specific content exclusively to local users. While there are APIs available for this purpose, I'm not sure how to implement them. I'm interested in creating a feature similar to Google Ads, where ads are tailored base ...

Navigate to Element ID with Nuxt.js on click

Currently, I am in the process of developing a Nuxt application and facing a challenge. I want the page to automatically scroll down to a specific element after clicking on a button. Interestingly, the button and the desired element are located within diff ...