Javascript Chrome未引发调整大小事件
如果你看这把小提琴: HTML:Javascript Chrome未引发调整大小事件,javascript,html,google-chrome,Javascript,Html,Google Chrome,如果你看这把小提琴: HTML: 调整div大小时,Chrome不会引发resize事件这是一个bug,还是正常?在IE和FF中,e.onresize返回未定义的,但在Chromee.onresize中返回null其中e是一个HTMLdiv。Chrome调试器中的intellisense检测到e上的onresize属性。是否应该在chrome中返回未定义的?IE和FF支持调整大小,但只支持窗口对象。我找不到合适的文档来解释什么时候应该提升resize,以及非window对象是否应该在Chrome
调整
div
大小时,Chrome不会引发resize
事件这是一个bug,还是正常?在IE和FF中,e.onresize
返回未定义的
,但在Chromee.onresize
中返回null
其中e
是一个HTMLdiv
。Chrome调试器中的intellisense检测到e
上的onresize
属性。是否应该在chrome中返回未定义的?IE和FF支持调整大小
,但只支持窗口
对象。我找不到合适的文档来解释什么时候应该提升resize
,以及非window
对象是否应该在Chrome中支持它 来自W3C规范:
调整文档视图大小后,用户代理必须发送此事件
调整窗口大小时会触发resize
事件,而不是您选择的任何元素。那么,chrome提供调整大小事件,然后在调整元素大小时不引发它有什么意义呢?正如我在问题中所说,在IE和FF中,div上没有onresize属性,但是chrome在div上有onresize属性。所有事件都可用于每个元素(在chrome中)。但这并不意味着浏览器会启动它。以
为例。它有事件onplay
和onprogress
,但这两个都是媒体事件,它们永远不会在
上触发,但它们仍然存在。
<h1>Instructions</h1>
<ol>
<li>Click on Resize Button</li>
<li>Observe no resize event is raised</li>
<li>Click on Check Height button</li>
<li>Observe height has changed</li>
</ol>
<button id="button">Resize</button>
<button id="button2">Check Height</button>
<br/>
<div id="map" style="position:fixed;width:600px;height:0px;border:1px solid black;">
<div id="root" style="position:absolute;left:0px;right:0px;top:0px;bottom:0px;border:1px solid red"/>
</div>
var button = document.getElementById('button');
button.addEventListener('click', process);
var root = document.getElementById('root');
root.addEventListener('resize', resize);
var console = document.getElementById('console');
var map = document.getElementById('map');
var button2 = document.getElementById('button2');
button2.addEventListener('click', function () {
log(root.offsetHeight);
});
log('ready to log');
function process() {
map.style.height = '400px';
}
function resize() {
var w = root.offsetWidth;
var h = root.offsetHeight;
log('resize event raised, dimensions are ' + w + " x " + h);
}
function log(text) {
console.appendChild(document.createTextNode(text));
console.appendChild(document.createElement('br'));
}