How to allow to type text in raphael object, say rect?

风流意气都作罢 提交于 2020-01-02 12:02:50

问题


I have created a Raphael rect like below: var rect1 = paper.rect(100,100,100,100)

Now, I want that as I click on the rect a cursor appears and user is allowed to type/key in some text

I am very very new to JS and Raphael.


回答1:


That's not a natural use of Raphael. Think of it primarily as a drawing library. If you look through the SVG specifications or any of the demos on the RaphaelJS page, you'll get the idea.

But Raphael integrates naturally with native Javascript or jQuery. I would place a borderless textarea on top of your rectangle and activate (and focus) it when the user clicks on the space, like so:

var paper = Raphael("canvas", 300, 300),
    rect1 = paper.rect(100,100,100,100).attr({fill: "#FFF"});

rect1.click(function(e) {
   $('#text').show(); 
   $('#text').focus(); 
});
​

http://jsfiddle.net/NtKKZ/

(Note that you need to fill the rectangle with white in order for the click event to fire.)



来源:https://stackoverflow.com/questions/14044337/how-to-allow-to-type-text-in-raphael-object-say-rect

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!