You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var elements =doc.querySelectorAll(listener.selector);
219
+
for(var j =0; j <elements.length; j++){
220
+
var element = elements[j];
221
+
// 确保回调函数只会对该元素调用一次
222
+
if(!element.ready){
223
+
element.ready=true;
224
+
// 对该元素调用回调函数
225
+
listener.fn.call(element, element);
226
+
}
227
+
}
228
+
}
229
+
}
230
+
231
+
// 对外暴露ready
232
+
win.ready= ready;
233
+
234
+
})(this);
235
+
236
+
ready('.foo', function(element){
237
+
// ...
238
+
});
239
+
240
+
```
241
+
169
242
## 参考链接
170
243
171
244
- Tiffany Brown, [Getting to know mutation observers](http://dev.opera.com/articles/view/mutation-observers-tutorial/)
172
245
- Michal Budzynski, [JavaScript: The less known parts. DOM Mutations](http://michalbe.blogspot.com/2013/04/javascript-less-known-parts-dom.html)
173
246
- Jeff Griffiths, [DOM MutationObserver – reacting to DOM changes without killing browser performance](https://hacks.mozilla.org/2012/05/dom-mutationobserver-reacting-to-dom-changes-without-killing-browser-performance/)
174
247
- Addy Osmani, [Detect, Undo And Redo DOM Changes With Mutation Observers](http://addyosmani.com/blog/mutation-observers/)
248
+
- Ryan Morr, [Using Mutation Observers to Watch for Element Availability](http://ryanmorr.com/using-mutation-observers-to-watch-for-element-availability/)
0 commit comments