Copy Code code as follows:
/**
* Window.onresize Event-specific event-binding device v0.1 Alucelx
* http://www.cnblogs.com/Alucelx/archive/2011/10/20/2219263.html
* <description>
* Used to solve multiple bugs of LTE IE8 & Chrome and other possible native window.resize events.
* </description>
* <methods>
* Add: Add event handle
* Remove: Delete event handle
* </methods>
*/
var onwindowresize = function () {
Event queues
var queue = [],
indexOf = Array.prototype.indexOf | | function () {
var i = 0, length = this.length;
for (; i < length; i++) {
if (this[i] = = Arguments[0]) {
return i;
}
}
return-1;
};
var isresizing = {},//Mark visual Area dimension status to eliminate multiple bugs for window.onresize events in LTE Ie8/chrome
Lazy = true,//lazy Execute tag
Listener = function (e) {//Event listener
var h = window.innerheight | | (document.documentelement && document.documentElement.clientHeight) | | Document.body.clientHeight,
w = window.innerwidth | | (document.documentelement && document.documentElement.clientWidth) | | Document.body.clientWidth;
if (h = = IsResizing.h && W = = ISRESIZING.W) {
Return
}else{
E = e | | window.event;
var i = 0, len = queue.length;
for (; i < Len; i++) {
Queue[i].call (this, e);
}
IsResizing.h = h,
ISRESIZING.W = W;
}
}
return {
Add:function (FN) {
if (typeof fn = = ' function ') {
if (lazy) {//Lazy execution
if (Window.addeventlistener) {
Window.addeventlistener (' Resize ', listener, false);
}else{
Window.attachevent (' onresize ', listener);
}
Lazy = false;
}
Queue.push (FN);
}else{}
return this;
},
Remove:function (FN) {
if (typeof fn = = ' undefined ') {
queue = [];
}else if (typeof fn = = ' function ') {
var i = indexof.call (queue, FN);
if (i >-1) {
Queue.splice (i, 1);
}
}
return this;
}
};
}.call (this);
Bind window's Resize event, use this object
Example:
Copy Code code as follows:
var _fn = function () {Document.body.innerHTML + = "1"};
Onwindowresize.add (_FN)
. Add (function () {Document.body.innerHTML + = "2"})
. Add (function () {Document.body.innerHTML + = "3"})
. Remove (_FN);