JavaScript Restrict Javascript Rotation Angle (With Propeller.js)

I am trying to figure out how to use propeller.js to restrict the rotation angle of an image. As of right now, if I spin my image twice, my output would read 720. I would like to make it so the element’s output will reset to 0 when spun over 360. In addition, I would like it to not output negative angles if I spin counterclockwise. For example going from 10 to 280.

Here is a codepen of where I am currently at: http://codepen.io/anon/pen/YyZaXK

$('img').propeller({inertia: 1, speed: 10,onRotate: function(){ console.log(this.angle); }});

Any suggestions?

Thanks!

Answer:1

Figured it out!

Using a Modulo made this work the way I wanted!

Here’s what I added:

(degrees + 360) % 360

Which resulted in:

$('img').propeller({inertia: 1, speed: 10,onRotate: function(){ console.log((this.angle + 360) % 360); }});
Answer:2

Looked in the Propeller.js source, found another solution. You can set zero angle if 360 is reached:

onRotate: function(){ 
  if(this.angle===360) 
  {
    this.virtualAngle = 0;
  }
  console.log(this.angle);
}
Answer:3

i tried with this RegEX no solution ^([a-zA-Z]{1})([0-9]{3})$ Test Case: Valid 123d f311 12d3 99A9

i tried with this RegEX no solution ^([a-zA-Z]{1})([0-9]{3})$ Test Case: Valid 123d f311 12d3 99A9

  1. regex three letter word
  2. regex three letter month
  3. regex three letters

I have an existing Django project and am adding a new app which consists of an API (using the rest-framework) and an angular app. This app contains one Django template, which simply serves as a way ...

I have an existing Django project and am adding a new app which consists of an API (using the rest-framework) and an angular app. This app contains one Django template, which simply serves as a way ...

I'm just a beginner I want to create button for remove clone but I can't. This is my code but it isn't work. Please help me to know where did I wrong. PS. Sorry for my poor English HTML <div ...

I'm just a beginner I want to create button for remove clone but I can't. This is my code but it isn't work. Please help me to know where did I wrong. PS. Sorry for my poor English HTML <div ...

I have a 'Phone Number' field in my web form. I also have a 'hidden' form field which contains a unicode phone icon [&#9742]. Entering a phone number is optional for my site visitors. So... if ...

I have a 'Phone Number' field in my web form. I also have a 'hidden' form field which contains a unicode phone icon [&#9742]. Entering a phone number is optional for my site visitors. So... if ...

  1. passing value to hidden form field jquery
  2. how to get input type hidden value in jquery
  3. pass value to hidden field jquery