Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API 文档 - dom 模块 #3

Open
cssmagic opened this issue Jul 8, 2015 · 1 comment
Open

API 文档 - dom 模块 #3

cssmagic opened this issue Jul 8, 2015 · 1 comment
Labels

Comments

@cssmagic
Copy link
Member

cssmagic commented Jul 8, 2015

API 文档 - dom 模块

JavaScript 变量  

为减少业务层对常用 DOM 元素的重复获取和包装,dom 模块预先缓存了这些元素的 Zepto 包装对象。在业务层可以直接使用。

.$win  

window 对象的 Zepto 包装对象。

示例

监听 resize 事件:

gearbox.dom.$win.on('resize', function (ev) {
    //...
})

.$root  

document.documentElement 对象(即 <html> 元素)的 Zepto 包装对象。

.$body  

document.body 对象(即 <body> 元素)的 Zepto 包装对象。

注意事项

为确保对 document.body 对象的正确获取,加载 Gearbox 的脚本标签须放置在页面的 <body> 标签内。当然,根据前端性能的最佳实践,所有外链脚本也确实应该放置在页面的最底部:

<html>
<head>...</head>
<body>
    ...
    <script src="gearbox.js"></script>
</body>
</html>

JavaScript 接口  

.is$Element(obj)  

判断是否为 Zepto 包装对象(或 Zepto 集合)。

如果外部环境没有加载 Zepto 但有 jQuery,则理论上此方法也可以判断 jQuery 包装对象(或 jQuery 集合)。

参数

  • obj -- 任意类型。需要判断的对象。

返回值

布尔值。判断结果。

示例

gearbox.dom.is$Element(gearbox.dom.$win)  // => true
@cssmagic cssmagic added the doc label Jul 8, 2015
@cssmagic
Copy link
Member Author

cssmagic commented Jul 13, 2015

与 Underscore.ext 的差异:

  • gearbox.dom.$root vs _.dom.$doc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant