Javascript 画布和jQuery?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3559424/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Canvas and jQuery?
提问by Qcom
Is it possible to use jQuery with the HTML5 <canvas>element? Or do I have to do it with plain JavaScript?
是否可以将 jQuery 与 HTML5<canvas>元素一起使用?还是我必须用普通的 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!
我只是想知道,因为我认为使用 jQuery 可以节省很多时间,但是我对<canvas>元素的用途一无所知,所以这可能是完全不可能的!
Anyone know if I canuse jQuery for this?
有谁知道我是否可以为此使用jQuery?
采纳答案by meder omuraliev
You can use jQuery to selectthe canvas element, but you'd have to use its own methods. A decent start would be https://developer.mozilla.org/en/canvas_tutorial.
您可以将 jQuery 用于select画布元素,但您必须使用它自己的方法。一个不错的开始是https://developer.mozilla.org/en/canvas_tutorial。
回答by BGerrissen
jQueryis a toolkit to interact and manipulate the DOM plus some extra neat ajax methods. Raphaeland/or Protovisare toolkits for visualisation.
jQuery是一个工具包,用于交互和操作 DOM 以及一些额外的简洁的 ajax 方法。 Raphael和/或Protovis是可视化工具包。
Processing.jsis a visualisation toolkit specifically for the canvas element.
Processing.js是一个专门用于画布元素的可视化工具包。
jQuery has one expertise, other toolkits have other expertise, though it's very much possible to use specialisation toolkits together ;)
jQuery 有一种专长,其他工具包也有其他专长,尽管非常有可能将专业化工具包一起使用 ;)
回答by Eric Rowell
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.
直接的答案是否定的,因为 jQuery 基于 DOM 查询和操作。Canvas 元素是使用 Canvas API 和 JavaScript 绘制的。如果您正在寻找一个好的画布库,您可以尝试KineticJS。它为画布应用程序添加了动画和事件支持。
回答by Joshua Pinter
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.
除了使用 jQuery 选择画布,然后使用内置画布方法,您还可以查看jCanvas,它是围绕画布 API 的“不错”包装器,您可能会发现它更容易/更好/更清晰。我知道我做到了。
This is what it looks like:
这是它的样子:
// Draw a circle
$("canvas").drawArc({
draggable: true,
fillStyle: "green",
x: 100,
y: 100,
radius: 50
});
回答by Yanick Rochon
回答by NazS2
the answer would be yes. you need to use the plain JavaScript..
答案是肯定的。你需要使用纯 JavaScript ..
how ever there is a jQuery plug-in that came in handy for me: http://calebevans.me/projects/jcanvas/
有没有一个 jQuery 插件对我有用:http: //calebvans.me/projects/jcanvas/
it gives you access to the canvas using the jQuery formatting that we are used for .
它使您可以使用我们使用的 jQuery 格式访问画布。
回答by SaKool
var canvas=($('<canvas width="200" height="1"></canvas>'))[0];

