- //判断数组是否包含值
- Array.prototype.contains = function(v){
- if(this.length == 0) return false;
- for(var i = 0; i < this.length; i++){
- if(this[i] !== v) return false;
- }
- return true;
- }
- //窗口改变大小事件
- //需要Array.prototype.contains的支持
- //在添加窗口改变大小事件的同时,如果实参t为true,则执行该函数
- //如果该函数被添加过,则不会再次添加,实参t为true,也不执行该函数
- var _resize = {
- cache : [],
- add : function(f,t){
- var a = this.cache;
- if(f instanceof Array){
- for (var i = 0; i < f.length; i++) {
- if (!a.contains(f[i])) {
- if(t) f[i]();
- this.cache.push(f[i]);
- $w.resize(f[i]);
- }
- }
- }else{
- if(!a.contains(f)){
- if(t) f[i]();
- this.cache.push(f);
- $w.resize(f);
- }
- }
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/2608201410339.html
来源: http://www.codesnippet.cn/detail/2608201410339.html