1

I have changed my cursor to an own image, and I want to rotate the image -120deg when I click in the canvas area.

here is the animation I want to have, but on my cursor instead of an image:

img {
    -webkit-transition: -webkit-transform 0.05s ease-in;
}

img:hover{
    -webkit-transform:rotate(-120deg)
}

My canvas:

<canvas id="gamemap" width="900" height="526" onclick="animateCursor()"></canvas>

JavaScript:

function animateCursor() {

}

css:

#gamemap {
    cursor: url('../Image/myimageup'), auto;
}

Is there any solution for this?

Jazi
  • 6,569
  • 13
  • 60
  • 92
Scrat
  • 96
  • 1
  • 12
  • Check this : http://stackoverflow.com/questions/9648131/jquery-rotate-cursor-angle – Jules Apr 22 '15 at 09:45
  • Yes, i have already checked that link. And there is only an animation for the image element in the html code. I want an animation for the cursor image. – Scrat Apr 22 '15 at 10:25

2 Answers2

0

DIRECT CHANGE

Just do canvas.style.cursor = new_image_path;

STEP ANIMATION
You could use an image array, containing list of images paths as string These images would be the same cursor image rotated at some angles by a step. Then, inside animateCursor function, do:

var img = 0, len = images.length, timer; // images is path array

function tick(){
    canvas.style.cursor = images[img] // new image every 5ms
    img++;

    if(img > len)
         clearTimeout(timer);
    else
         timer = setTimeout(tick, 5ms);
}

timer = setTimeout(tick, 5); // 5 ms
Gaurang Tandon
  • 6,504
  • 11
  • 47
  • 84
0

try this

function animateCursor() {
  $('#gamemap').css('-webkit-transition','-webkit-transform 0.05s ease-in');
  $('#gamemap').hover(function(){
    $('#gamemap').css('-webkit-transform','rotate(-120deg)');
  });
  $('#gamemap').css('cursor','url("../Image/myimageup"), auto');
}
Theo
  • 1,932
  • 4
  • 17
  • 40