草绘与JS [英] Sketching with JS

查看:79
本文介绍了草绘与JS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难想象这个。

假设你有一个使用JS构建的草图应用程序。例如: http://intridea.github.com/sketch.js/

Let's say you have a sketch app built with JS. For example: http://intridea.github.com/sketch.js/

并且你想在用户绘图之后存储它们。这样,只要有人访问该网站,它加载所有以前的图纸。

And you want to store the user's drawing after they draw something. So that whenever someone visits the site it loads all the previous drawings. It's a bit faking realtime multiuser drawing, because making it really realtime is not an option at the moment.

服务器端我使用的是PHP和MySQL,我不需要这么做,因为它是真正的实时的。 。

Server-side I am working with PHP and MySQL, I don't know if that's any good for this.

谢谢。

推荐答案

使用 $('#myCanvas')。sketch()),将一个函数调用 toDataURL()(在HTML元素上,而不是jQuery元素)。您可以将此函数返回的数据上传到您的服务器。

The canvas you apply 'sketch.js' to (using $('#myCanvas').sketch()), has a function that is called toDataURL() (on the HTML element, not the jQuery element). You can upload the data this function returns to your server.

$('#upload').click(function () {
    $.post('/upload_image.php', { data: $('#myCanvas').get(0).toDataURL() }, function () {
         alert('uploaded');
    });
});

您可以通过加载发布到服务器的数据来恢复画布。请参见此处: http://www.html5canvastutorials.com/advanced/html5- canvas-load-image-data-url /

You can restore the canvas by loading in the data that was posted to your server. See for example here: http://www.html5canvastutorials.com/advanced/html5-canvas-load-image-data-url/.

这篇关于草绘与JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆