我正在使用PaperJS制作一个帆布应用程序,在每个气球中生成带有文本的气球。但是,我希望允许用户编辑每个气球内的文本,以便他们想说什么就说什么。
是否允许用户编辑PaperJS TextItem,就像HTML输入字段一样?
发布于 2015-12-28 04:09:52
简单地说,答案是否定的,除非您从零开始实现并行功能。我所使用的解决方案是让用户绘制一个矩形,然后使用绝对定位将矩形覆盖在画布上的文本框或文本区域相同的位置。它需要额外的抽象级别,但可以很好地工作。
这并不简单,但这里有一个基本的框架,展示了它的工作原理。我可能会有时间让它在线,但这将需要一点,所以我不知道什么时候。我也在从一个更大的系统中快速提取这个信息,所以如果你发现任何错误,请告诉我。
var rect;
var tool = new paper.Tool();
// create a paper rectangle. it's just a visual indicator of where the
// text will go.
tool.onMouseDown = function(e) {
rect = new paper.Path.Rectangle(
from: e.downPoint,
to: e.downPoint,
strokeColor: 'red',
);
}
tool.onMouseDrag = function(3) {
if (rect) {
rect.remove();
}
rect = new paper.path.Rectangle({
from: e.downPoint,
to: e.point,
strokeColor: 'red'
});
}
tool.onMouseUp = function(e) {
var bounds = rect.bounds;
var textarea = $("<textarea class='dynamic-textarea' " +
"style='position:absolute; left:" + bounds.x +
"px; top:" + bounds.y + "px; width: " + bounds.width +
"px; height: " + bounds.height +
"px; resize;' placeholder='Enter text'></textarea>");
// make the paper rectangle invisible for now. may want to show on
// mouseover or when selected.
rect.visible = false;
// add the text area to the DOM then remember it in the path
$("#parent-div").append(textarea);
rect.data.textarea = textarea;
// you may want to give the textarea focus, assign tab indexes, etc.
};https://stackoverflow.com/questions/34484447
复制相似问题