最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Detect word wrap in contenteditable span - Stack Overflow

programmeradmin1浏览0评论

I have contenteditable span with a max-width setting that allows the user to enter text. What I'm looking to do is detect when the user reaches this width limit and a new line is displayed on the page. I am trying to create a WYSIWYG editor that creates text, (in SVG), exactly the way it looks in the contenteditable span when the user presses enter. I have successfully captured the enter event, so that is not an issue, I am looking for a way to either detect the word wrap, or calculate where it should occur. Any help is appreciated. (I can post sample code if needed)

I have contenteditable span with a max-width setting that allows the user to enter text. What I'm looking to do is detect when the user reaches this width limit and a new line is displayed on the page. I am trying to create a WYSIWYG editor that creates text, (in SVG), exactly the way it looks in the contenteditable span when the user presses enter. I have successfully captured the enter event, so that is not an issue, I am looking for a way to either detect the word wrap, or calculate where it should occur. Any help is appreciated. (I can post sample code if needed)

Share Improve this question asked Mar 23, 2012 at 19:45 RestingRobotRestingRobot 2,9781 gold badge25 silver badges36 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

When the height of the element changes, you know you have word-wrap occurring.

Monitor for a change event and see if the height changed. If it did, you have a word-wrap (or un-wrap). I threw together an example:

http://jsfiddle/eZDRD/

发布评论

评论列表(0)

  1. 暂无评论