Click here to Skip to main content
14,391,651 members
Rate this:
Please Sign up or sign in to vote.
$('#myCanvas2').on('click', function(e) {

this.removeAttribute('style');
var r = Math.random();

var deg = 3000 + Math.round(r * 500);
deg = Math.pow(-1,i) * deg;

var css = '-webkit-transform: rotate(' + deg + 'deg);';
this.setAttribute('style', css);
i++;
});

What I have tried:

var canvas = document.getElemementById('myCanvas2').onclick = function(e){
canvas.removeAttribute('style');
var r = Math.random();

var deg = 3000 + Math.round(r * 500);
deg = Math.pow(-1,i) * deg;

var css = '-webkit-transform: rotate(' + deg + 'deg);';
canvas.setAttribute('style', css);
i++;
}
Posted
Updated 13-Jun-17 18:56pm

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

document.getElementById('myCanvas2').onclick = function (e) {
                        this.removeAttribute('style');
                        var r = Math.random();

                        var deg = 3000 + Math.round(r * 500);
                        deg = Math.pow(-1, i) * deg;

                        var css = '-webkit-transform: rotate(' + deg + 'deg);';
                        this.setAttribute('style', css);
                        i++;
                    }
   
Comments
rhemielco 15-Jun-17 2:49am
   
thanks for the reply, i would be please if you answer this question if is it necessary to put the get context(2d) on the code and is it possible to convert the css style animation to purely javascript like deleting the remove and set attribute and instead put all the codes in the javascript including the transfom: rotate.

looking forward for your reply thnks in advance
Karthik_Mahalingam 15-Jun-17 2:54am
   
its is a style, this has nothing to do with js, you will have to use as it is.
rhemielco 15-Jun-17 3:44am
   
thanks for your reply, in my problem when i try my code in a web hosting site i don't see the rotating image on the web only the circle images. So do i need to put get context(2d) or it's just the style that affecting the code? thanks in advance..
Karthik_Mahalingam 15-Jun-17 3:47am
   
check in chrome console for any error ?
rhemielco 15-Jun-17 8:11am
   
thanks you very much for your help
Karthik_Mahalingam 15-Jun-17 11:03am
   
welcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100