Skip to main content
Dirlo
Inspiring
December 14, 2017
Question

Rotate an image with a button in html5

  • December 14, 2017
  • 5 replies
  • 5361 views

...

Hello !...

I'm using Captivate 2017, and I want to rotate an image when I click on a button...

Everything is fine in the browser, but when using html5 it doesn't work anymore...

So I try to use jQueryRotate.js.

So I added this js file in the assets/js/ folder and added it in the html file :

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

And my javascript on the button is this :

$(this).click(function() {

$('#Regle_3').rotateAnimation(angle);

(angle+=2)%90;

});

(Regle_3 is the name of my image)

I try for too long now... So I need your help !!...

Thanks in advance !...

...

This topic has been closed for replies.

5 replies

Jeremy Shimmerman
Participating Frequently
January 3, 2018

Not sure if you have already found your solution.  I just created a video on this - maybe it will help. Also I don't see the .rotateAnimate function on the jQueryRotate website. 

https://elearning.adobe.com/?p=20807

Dirlo
DirloAuthor
Inspiring
January 4, 2018

...

You are a javascript magician !...

I had first problem to copy/paste your code and make it work because of problems with the " and ' characters !!...

And the javascript window is not so big in Captivate !...

But when I found the trick, it works fine !... And even with a drag and drop effect !...

I'm so happy !...

Great Thx !...

...

Dirlo
DirloAuthor
Inspiring
January 24, 2018

...

I'm still having a problem...

I have an horizontal ruler, which I want to drag and rotate if needed.

I can drag the ruler... I can rotate it using JQueryRotate (Thx to Jeremy's post)... But when I try to drag it again, my object comes back to its initial horizontal position (and when I stop dragging it, it appears again in its rotated shape).

But I want to drag it in the rotated shape...

I think I have to use Jquery to drag it (and not use the dragging widget) but I don't manage to do it so far...

I will open a new post to try to find more help !...

...

Stagprime2687219
Brainiac
December 16, 2017

Here is a link to my little working demo.

It was created with Captivate 9 and I cannot guarantee it will convert to something else well.

Rotate Drag Source Object Demo  ruler.cptx (900K)

In summary, it has the following:

  1. Two variables - degree and concatValue - current values shown in boxes by the buttons
  2. Two buttons - each button executes three lines of javascript - one decreases the angle, one increases it.
    1. First line of javascript increases or decreases the angle value by the desired value
    2. Second line concatenates the word degree with the current value for degree
    3. Third line changes the state of the image using the concatenated name which matches the state name.
  3. A ruler image with default 'Normal' state and four additional states to show 5 degree changes
  4. Three random lines
  5. Ruler as drag source

Hopefully many will find a good use for this.

Dirlo
DirloAuthor
Inspiring
December 16, 2017

...

You are a magician !!...

(My mistake was surely to produce the multiple states before the dragging function... ?...)

I could convert the source in Cpt 2017...  Everything is ok !... (even in html5 !...)

Except... ... When I stop dragging the ruler, it comes back to its original position... (I try to uncheck the come-back option but it doesn't change anything ???...)

I think I could reproduce it my way with your source and I will tell you if it's ok !... (Be patient... I start to play with other things... Captivate is so captivating !!...)

Great thx anyway !...

...

Stagprime2687219
Brainiac
December 16, 2017

Yea, I did it that way since if you have the object rotate away from the original position, it skews funny and does not look right.

It works better to rotate it from the original position where the states were created and then move it.

If you open the object actions panel on the D&D tab for the blue target box, you can set the ruler as an accepted source and see what I mean.

If you want to do that, you should also bring that box up on the layers so it is directly below the ruler and bring the opacity down. If you don't, the ruler will be difficult to pick up again.

Stagprime2687219
Brainiac
December 15, 2017

Good News!

I have discovered a possible solution for you.

It does mean creating many states for your image though.

I created a sample that uses only four states that increment by 5 degrees. (0, 5, 10, and 15)

You can make whatever increment suits your application.

Clicking the plus and minus buttons will adjust the ruler and it remains draggable.

I created two variables. Degree and concatValue

I used javascript to concatenate the word degree with the value of the variable to make

degree0, degree5, degree10, degree15, etc.

My image states have matching names

Javascript then changes the state by inserting the concatenated value for the state name.

I have a plus and minus button. The plus button has the script below and the minus button simply has the degree minus 5 in the first line.

window.degree=degree+5

window.concatValue=String("degree").concat(degree);

cp.changeState("ruler",window.concatValue);

Here is a short video showing the mockup I did.

Dirlo
DirloAuthor
Inspiring
December 16, 2017

...

Effectively, it looks great !...

I will start to work on your method immediately !... But not sure I can reproduce it...

Surely, I'll be back there with new questions !...

Big thanks anyway !...

...

Dirlo
DirloAuthor
Inspiring
December 16, 2017

...

So...

I think I did all you mention in your answer... but unsuccessfully !...

I manage to "rotate" the ruler (only once)...

But as soon as I put the drag option, the "rotation" is no more available...

I want to send you my try... But don't find a way to do so...

(Write you private message... )

...

Stagprime2687219
Brainiac
December 14, 2017

Do you need to see the item moving?

What about clicking the button and having it change state?

Would that work?

Dirlo
DirloAuthor
Inspiring
December 14, 2017

...

I think the problem is linked with the drag and drop effect !...

I just duplicated the frame and deleted the D&D effect and it's ok !!!...

But I need the image to move !... (it's a graduated ruler that I want to use to measure segments)

...

Lilybiri
Brainiac
December 14, 2017

That is VERY important information that was totally lacking in your original question.  Drag&Drop objects are in a different situation. Which action did you use to apply the effect: the Success action of the D&D slide or object actions?

Lilybiri
Brainiac
December 14, 2017

I use a Rotate To effect for such a purpose, create a custom effect and apply it with an advanced or simple action.

Do you say that this is not functioning? If yes, how did you test: you need to test the published project after uploading to a webserver.

Dirlo
DirloAuthor
Inspiring
December 14, 2017

...

Thx for your quick answer !...

So I try to add an effect (didn't think of it until your advice !!...)

Works fine in the browser... but again I have trouble with the html5 output !!!...

(Sorry... didn't test it after publishing... !!!... I try it now !!...)

...

Dirlo
DirloAuthor
Inspiring
December 14, 2017

...

I still have problem...

This is where my project is :

http://soutien67.fr/math/activites/longueur/Longueurs_02/

Its on the last diapo...

I want to rotate the ruler when I click on the button on the right side...

Thx again for your help !...

...