为dom元素添加resize事件
// 添加resize 事件
function addresize(dom, fn) {
var w = dom.offsetWidth,
h = dom.offsetHeight,
oldfn = window.onresize;
if (oldfn) {
window.onresize = function () {
oldfn.call(window);
if (dom.offsetWidth != w || dom.offsetHeight != h) {
w = dom.offsetWidth;
h = dom.offsetHeight;
fn.call(dom);
}
}
} else {
window.onresize = function () {
if (dom.offsetWidth != w || dom.offsetHeight != h) {
w = dom.offsetWidth;
h = dom.offsetHeight;
fn.call(dom);
}
}
}
}