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?

2

2 Answers 2

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');
}
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
2
  • I have tried "Direct Change" but it only gives me the default cursor back.. Seems like the script not find the path. "../image/myimage.png"
    – Scrat
    Apr 22, 2015 at 10:33
  • @Jigfors Make sure to wrap it inside "url"s parentheses. Apr 22, 2015 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.