js实现计算文字宽度
2016-05-17 08:50
417 查看
coffeescript转化之后
_textSize = (fontSize, text) -> span = document.createElement("span") span.style.fontSize = fontSize result = {} result.width = span.offsetWidth result.height = span.offsetWidth span.style.visibility = "hidden" document.body.appendChild(span) if not (typeof span.textContent is "undefined") span.textContent = text else span.innerText = text result = span.offsetWidth - result.width span.parentNode.removeChild(span) return result
相关文章推荐
- 使用coffeescript编写node.js项目的方法汇总
- coffeescript使用的方式汇总
- jfinal-coffeescript使用java实现coffeescript的动态编译
- 使用coffeescript-maven-plugin,实时监控coffee文件的编译,只需一步配置
- 一个后端的前端学习之旅——4.第一个demo上线以及关于前端框架我的看法
- CoffeeScript环境安装for mac
- sublime text2 node.js 开发配置
- 你需要掌握的三种编程语言
- ruby on rails - ubuntu篇
- coffeescript 汉字转拼音代码
- coffeeScript实时同步到服务器,自动编译并重启nodejs服务
- 构建移动Web应用程序的技术堆栈
- JAVASCRIPT MVC架构之旅
- 阅读和实践是最好的老师
- Java开源建站工具
- 如何成为“10倍效率”开发者
- 11款主流的开源编程工具
- 10x 开发者
- Java开源工具 网站开发工具清单
- Coffee Script的windows环境下的初步安装使用