使用画布元素作为文本区域
I'm looking for a straight forward description of how to use a canvas element sort of like a text area.
I have seen projects such as Ace. Just wondering how to go about writing to the area as if it where a textarea. Just plain text, nothing fancy.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Ace 曾经是 Mozilla Skywriter,又曾经是 Mozilla Bespin。
如果您愿意深入研究 Bespin 的代码并根据它创建自己的代码,那么 Bespin 的代码实际上很容易理解,但这有点像傻瓜的任务。 Canvas 规范实际上特别建议不要这样做:
Ace used to be Mozilla Skywriter, which used to be Mozilla Bespin.
The code for Bespin is actually pretty simple to understand if you are willing to dig through it and make your own based on it, but it is sort of a fool's errand. The Canvas spec actually advises specifically against this:
使用 chrome 检查现场演示表明他们使用 div 和 span 来实现这一点。闪烁的光标是一个似乎定期在隐藏和可见之间切换的 div。我认为他们只是检查事件中按下的键并将其写入该行的相应范围。
Inspecting the live demo with chrome shows they use divs and spans to achieve this. The blinking cursor is a div that seems to switch between hidden and visible on a regular basis. I would think that they just check the pressed key from the event and write it to the corresponding span for the line.