Rotate Objects with JQuery
December 19, 2017
Rotate Objects with JQuery
December 19, 2017
Newbie 18 posts
Followers: 44 people

Learn JQuery Rotate,

Also some basic javascript programming, embedding external javascript libraries into your projects, and more!

 

 

Here are the basic steps to creating the ‘seesaw – type’ object:

1. Create the object and give it an id name ‘bar’

2. Create two variables ‘sRot’, and ‘eRot’. Give both a value of 0

3. Create two buttons that execute javascript.  (unclick advance project )

Javascript code for right button is:

sRot = eRot;
eRot = eRot + 7;
$(“[id=’barc’]”).rotate({angle:sRot,animateTo:eRot,easing:$.easing.easeInOutExp});

Javascript code for left button is:

sRot = eRot;
eRot = eRot – 7;
$(“[id=’barc’]”).rotate({angle:sRot,animateTo:eRot,easing:$.easing.easeInOutExp});

 

4. Download jQueryRotate.js at http://jqueryrotate.com

5. Publish your project

6. Paste jQueryRotate.js in ‘assets/js’ folder

7. Edit index.html file (I use Sublime Text Editor)

Change the var lJSFile to include the jQueryRotate.js file

var lJSFiles = [  ‘assets/js/jquery-1.11.3.min.js’,’assets/js/CPM.js’,’assets/playbar/playbarScript.js’,’assets/js/jQueryRotate.js’ ];

8. Save index.html and launch the index.html in your browser.  Enjoy your rotating bar!

 

 

 

All Comments
Sort by:  Most Recent
Oct 1, 2020
Oct 1, 2020

Great post! Thank you.

One thing here. I thought you just write $(“#name”) in jQuery.

You used this:  $(“[id=’barc’]”). Is it about Captivat API or something else?

Like
()
(1)
Oct 13, 2020
Oct 13, 2020
>
Piotr69
's comment

I can answer my onw question. I tested it and this shorter jquery notation works. So you can shorten the code a bit by using this syntax:  $(“# yourId”). Of course, instead of “yourId” you insert your id’s name . Just a remark.

Like
()
Mar 6, 2018
Mar 6, 2018

This is great !…

But I’m still trying to find a solution for dragging AND rotating the same object !

I try many times to drag an object using javascript (and not the Cpt widget) without any success so far…

Maybe you could help ?

Thx in advance !

Like
()
Dec 20, 2017
Dec 20, 2017

Great blog. Thank you.

Like
(1)