Javascript 如何在html5中获取已编辑画布的html文件
我正在尝试创建一个网站,通过在画布上拖放元素来帮助用户创建页面。用户应该能够保存已编辑画布的html文件。我不知道如何将对画布所做的更改转换为html文件。我认为不可能从画布中获取标记。我已经搜索了一个月,但找不到有效的解决方案。但可能有些专家可能知道。祝你好运,伙计。画布基本上只是一个位图图像。在画布上绘制的任何内容都存储为像素,而不是元素。因此对画布的更改只是像素值的更改。要实现您的愿望,您需要在代码中将“元素”存储为“对象”,其中每个“对象”存储“元素”所需的所有数据 然后可以打开一个新窗口,并使用document.writeln将代码导出到其中 下面的代码可能会让您知道需要什么样的东西Javascript 如何在html5中获取已编辑画布的html文件,javascript,jquery,html5-canvas,html-editor,Javascript,Jquery,Html5 Canvas,Html Editor,我正在尝试创建一个网站,通过在画布上拖放元素来帮助用户创建页面。用户应该能够保存已编辑画布的html文件。我不知道如何将对画布所做的更改转换为html文件。我认为不可能从画布中获取标记。我已经搜索了一个月,但找不到有效的解决方案。但可能有些专家可能知道。祝你好运,伙计。画布基本上只是一个位图图像。在画布上绘制的任何内容都存储为像素,而不是元素。因此对画布的更改只是像素值的更改。要实现您的愿望,您需要在代码中将“元素”存储为“对象”,其中每个“对象”存储“元素”所需的所有数据 然后可以打开一个新窗
newwindow=window.open('','_blank');
newwindow.document.writeln('<!DOCTYPE HTML>');
newwindow.document.writeln('<html>');
newwindow.document.writeln('<head>');
newwindow.document.writeln('<style>');
newwindow.document.writeln('#element0 {');
newwindow.document.writeln('background:'+ obj0.background+';');
newwindow.document.writeln('width:'+ obj0.width+';');
newwindow.document.writeln ('}');
newwindow.document.writeln('</style>');
newwindow.document.writeln('</head>');
newwindow.document.writeln('<body>');
newwindow.document.writeln('<div id="element0"></div>');
newwindow.document.writeln('</body>');
newwindow.document.writeln('</html>');
newwindow.document.writeln('<html>');
newwindow.document.close();
newwindow=window.open('''u blank');
newwindow.document.writeln(“”);
newwindow.document.writeln(“”);
newwindow.document.writeln(“”);
newwindow.document.writeln(“”);
newwindow.document.writeln('#element0{');
newwindow.document.writeln('background:'+obj0.background+';');
newwindow.document.writeln('width:'+obj0.width+';');
newwindow.document.writeln('}');
newwindow.document.writeln(“”);
newwindow.document.writeln(“”);
newwindow.document.writeln(“”);
newwindow.document.writeln(“”);
newwindow.document.writeln(“”);
newwindow.document.writeln(“”);
newwindow.document.writeln(“”);
newwindow.document.close();
希望这有帮助Canvas在这里除了可视化掉到画布上的对象之外,对您没有任何帮助 你需要在场景后面的“阴影”结构中记录你放置的物体。也就是说:在内部构建对象列表,然后可以将其用作源数据来渲染:
- 它的画布可视化
- 来自它的原始HTML代码
myElement
是一个预定义的对象,您可以预先设置它来保存给定的参数
然后将对象推送到对象堆栈并渲染到画布:
myObjects.push(o);
for(var i = 0, o; o = myObjects[i]; i++) {
/// draw the look of this object here to canvas
}
当您需要HTML版本时,您也可以这样做:
for(var i = 0, o; o = myObjects[i]; i++) {
var el = '<' + o.type + ' id="' + o.id + ' .... other things here
}
for(变量i=0,o;o=myObjects[i];i++){
瓦雷尔
for(var i = 0, o; o = myObjects[i]; i++) {
var el = '<' + o.type + ' id="' + o.id + ' .... other things here
}