开发者

Canvas and jQuery?

Is it possible to use jQuery with the HTML5 <canvas> element? Or do I have to do it with plain JavaScript?

I'm just wondering, because I think I could save a lot of time with using jQuery, but I have no clue about the <canvas> element's uses yet, so it may be completely impossible!

开发者_开发问答

Anyone know if I can use jQuery for this?


You can use jQuery to select the canvas element, but you'd have to use its own methods. A decent start would be https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial.


jQuery is a toolkit to interact and manipulate the DOM plus some extra neat ajax methods. Raphael and/or Protovis are toolkits for visualisation.

Processing.js is a visualisation toolkit specifically for the canvas element.

jQuery has one expertise, other toolkits have other expertise, though it's very much possible to use specialisation toolkits together ;)


The direct answer is no because jQuery is based on DOM querying and manipulation. Canvas elements are drawn using the Canvas API with JavaScript. If you're looking for a good canvas library, you might try out KineticJS. It adds animation and event support for canvas applications.


jCanvas

Besides using jQuery to select the canvas and then using the built-in canvas methods, you can also check out jCanvas, which is a "nice" wrapper around the canvas API that you might find easier/better/clearer. I know I did.

This is what it looks like:

// Draw a circle
$("canvas").drawArc({
  draggable: true,
  fillStyle: "green",
  x:         100, 
  y:         100,
  radius:    50
});


Take a look at Raphaël. This is yet the best project I've seen so far using something similar to canvas (thus supported in all major browsers) and Javascript (JQuery).


the answer would be yes. you need to use the plain JavaScript..

how ever there is a jQuery plug-in that came in handy for me: http://calebevans.me/projects/jcanvas/

it gives you access to the canvas using the jQuery formatting that we are used for .


var canvas=($('<canvas width="200" height="1"></canvas>'))[0];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜