Skip to content

Instantly share code, notes, and snippets.

@lukejones
Created July 29, 2013 09:49
Show Gist options
  • Save lukejones/6103291 to your computer and use it in GitHub Desktop.
Save lukejones/6103291 to your computer and use it in GitHub Desktop.
Detect browser height
function browserHeight(){
var headerHeight = $(window).height();
$(".header").css('height',headerHeight); // I wanted to subtract pixels from this value, e.g. change 970px to 920px
};
$(document).ready(browserHeight);
@danmatthews
Copy link

function browserHeight(){
var headerHeight = parseInt($(window).height()) - 50;
$(".header").css('height',headerHeight+'px'); // I wanted to subtract pixels from this value, e.g. change 970px to 920px
};
$(document).ready(browserHeight);

@jackfranklin
Copy link

You can use parseInt to abstract the number.

var num = parseInt(headerHeight, 10); // => 970
var newNum = num - 70;
$(".header").css("height", newNum + "px"); // might not be required, jQuery defaults to px IIRC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment