Skip to content

Instantly share code, notes, and snippets.

@first-developer
Created May 29, 2013 05:26
Show Gist options
  • Save first-developer/5668157 to your computer and use it in GitHub Desktop.
Save first-developer/5668157 to your computer and use it in GitHub Desktop.
A CodePen by first-developer. Compute window size on resizing - Code use to compute window size when the browser is resizing
<div class="m"></div>
var windowResize = function(fun){
var oldresize = window.onresize;
window.onresize = function(e) {
if (typeof oldresize == 'function') oldresize(e);
fun(e);
}
};
var res = function (e) {
console.log([e.srcElement.outerWidth, e.srcElement.outerHeight]);
var h = $(".m").outerWidth();
console.log("Div width ", h);
};
// jQuery version
/*$(window).on("resize", function(e) {
console.log($(e.target).width());
});*/
windowResize(res);
.m {
display: block;
width: 100%;
height:20px;
background-color: #000;
box-sizing: border-box;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment