admin管理员组文章数量:1330609
I'm trying to detect when the onresize
event ends in a browser. If I use the onresize
event, in Firefox it seems to be fired only once, after the resize event ends, which is exactly what I want. But if I try in IE, the onresize
event gets fired many times during the resize.
I also try the onresizeend
event, advertised in MSDN. But it does not seem to get fired at all, neither in Firefox, nor in IE. I use the following code:
<html>
<head>
<script>
<!--
function doLog(message)
{
document.getElementById("log").innerHTML += "<br/>" + message;
}
function doResize()
{
doLog("plain resize");
}
function doResizeEnd()
{
doLog("resize end");
}
-->
</script>
<style>
<!--
#log {
width: 400px;
height: 600px;
overflow: auto;
border: 1px solid black;
}
-->
</style>
</head>
<body onresize="doResize();" onresizeend="doResizeEnd();">
<div id="log"/>
</body>
</html>
Any ideas why this does not work? Maybe the onresizeend
event is not supported? In this case, how can I detect when the resize
event has ended?
I'm trying to detect when the onresize
event ends in a browser. If I use the onresize
event, in Firefox it seems to be fired only once, after the resize event ends, which is exactly what I want. But if I try in IE, the onresize
event gets fired many times during the resize.
I also try the onresizeend
event, advertised in MSDN. But it does not seem to get fired at all, neither in Firefox, nor in IE. I use the following code:
<html>
<head>
<script>
<!--
function doLog(message)
{
document.getElementById("log").innerHTML += "<br/>" + message;
}
function doResize()
{
doLog("plain resize");
}
function doResizeEnd()
{
doLog("resize end");
}
-->
</script>
<style>
<!--
#log {
width: 400px;
height: 600px;
overflow: auto;
border: 1px solid black;
}
-->
</style>
</head>
<body onresize="doResize();" onresizeend="doResizeEnd();">
<div id="log"/>
</body>
</html>
Any ideas why this does not work? Maybe the onresizeend
event is not supported? In this case, how can I detect when the resize
event has ended?
1 Answer
Reset to default 5From MSDN onresizeend()
Only content editable objects can be included in a control selection. You can make objects content editable by setting the contentEditable property to true or by placing the parent document in design mode.
That explains why it's not firing for you. I suspect you don't want to enable contentEditable, so why not set a timer.
var resizeTimer = 0;
function doResize()
{
if (resizeTimer)
clearTimeout(resizeTimer);
resizeTimer = setTimeout(doResizeEnd, 500);
}
It's not perfect but hopefully will be good enough.
本文标签: javascripthtml onresizeend eventor equivalent way to detect end of resizeStack Overflow
版权声明:本文标题:javascript - html onresizeend event, or equivalent way to detect end of resize - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742270496a2444213.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论