jQuery提供了resize方法,官方有个实用的小例子:
$( window ).resize(function() {
$( "body" ).prepend( "<div>" + $( window ).width() + "</div>" );
});
拖拽浏览器,可以获得每次拖拽后的浏览器宽度。那么我们就结合setTimeout
实现拖拽后执行某个事件,于是有了以下内容:
var resizeId;
$(window).resize(function() {
clearTimeout(resizeId);
resizeId = setTimeout(doneResizing, 500);
});
function doneResizing(){
//whatever we want to do
}
有关原生onresize
说明,原生方法在单机测试,ie8resize功能正常,可以使用
// html
<div id="wwidth"></div>
<div id="wheight"></div>
//script
window.onload = function () {
var spanplus = 1;
var wWidth = document.querySelectorAll('#wwidth')[0];
var wHeight = document.querySelectorAll('#wheight')[0];
function resizeTest(){
wWidth.textContent = window.innerWidth;
wHeight.textContent = window.innerHeight;
spanplus++;
alert(spanplus);
}
window.onresize = resizeTest;
};
网友评论