简体   繁体   English

以下 jQuery 代码的 JavaScript 等价物是什么?

[英]What is the JavaScript equivalent of the following jQuery code?

I want to make spinning wheel but instead of rotating wheel i want to rotate the pointer.我想制作纺车,但我想旋转指针而不是旋转轮。 I have the following jQuery code snippet which rotates a pointer but I don't know how to convert this jQuery snippet into JavaScript.我有以下旋转指针的 jQuery 代码片段,但我不知道如何将此 jQuery 片段转换为 JavaScript。

jQuery code: jQuery代码:

$( 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');
});

i want to do something like this https://i.stack.imgur.com/0KArr.gif我想做这样的事情https://i.stack.imgur.com/0KArr.gif

Here is a simple example, that shows how you could solve it with vanilla JS and CSS by using CSS animations which can be toggled on and off via JS.这是一个简单的例子,它展示了如何通过使用可以通过 JS 打开和关闭的 CSS 动画,使用 vanilla JS 和 CSS 来解决它。

 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>

Depending on which browsers you want/have to support, you might have to add vendor prefixes in the CSS code.根据您想要/必须支持的浏览器,您可能需要在 CSS 代码中添加供应商前缀。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM