简体   繁体   中英

How do I get the current rotation angle with jCanvas animation?

I can't figure out how to get the current rotation angle of an arch in jCanvas. layer.rotate only seems to provide me with the original setting of rotate, when I'd really like to change its behavior when it hits a certain angle.

I have an example setup on jsfiddle to demonstrate the problem.

Any insight would be appreciated.

are you looking for this value $('#rot').val()

while (i < 1000) {
        setTimeout(function() { rotate() }, 1000);
        alert( $('#rot').val());
        i += 1;
    }

The animateLayer() and animateLayerGroup() methods support the same alternate syntax as jQuery's animate() method, which allows for a step callback:

// Cache canvas element
var $canvas = $("canvas");

// Draw and animate
$canvas.drawArc({
  layer: true,
  name: 'arcy',
  fillStyle: "#000",
  x: 100, y: 100,
  radius: 50,
  start: 135, end: 45
});
$canvas.animateLayer('arcy', {
  rotate: 360
}, {
  // Use the step callback to run a function on every frame
  step: function(now, fx, layer) {
    console.log(layer.rotate);
  }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM