Usual way to add resize event (to listen window size changed) is this:
//works just fine
window.addEventListener("resize", function(){console.log('w')}, true)
but I want to add this event handler to document.body
or even better to document
(don't ask me why, but i can't use window)
//this dosn't work
document.body.addEventListener("resize", function(){console.log('b')}, true)
//this also dosn't work
document.addEventListener("resize", function(){console.log('d')}, true)
the problem is that this dosn't work. I really don't understand why? MB i missed something?
this works ( but ones again i want to use addEventListener
)
document.body.onresize = function(){console.log('a')}
So why document.addEventListener("resize", function(){console.log('d')}, true)
doesn't work?
UPD #1
Is there a way to capture window.onresize on something other that window?
UPD #2
And if window
is the only object that get resized then WHY this works? o_O
document.body.onresize = function(){console.log('a')}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…