I need to size a vertical range control based on the available height in the browser. I just about have it, except I think there is some type of a padding/border/margin issue that I can't get around. Although it sizes itself according to the height of the browser, my range control always goes off the bottom of the page by a few pixels.
This is how I'm getting the height:
var height = window.innerHeight
|| document.documentElement.clientHeight
|| document.body.clientHeight;
then using it to set the slider height:
document.getElementById("slider").setAttribute('style', "height :" + height + "px");
I know that clientHeight returns the height INCLUDING padding, so I've been thinking that I just need to get the top padding and subtract it. Problem is that when I get the padding as shown here, it is zero (alert writes out 0px):
alert("top pad: " + window.getComputedStyle(document.documentElement, null).getPropertyValue('padding-top'));
Meanwhile, the CSS for the slider looks like this, so I don't think its own padding/border/margins are responsible:
.sliderStyle {
height: 860px;
width: 2%;
-webkit-appearance: slider-vertical;
padding-top: 0px;
margin: 0px;
border: 0px;
}
The only thing in the body of the HTML is the range control:
<input id="slider" class="sliderStyle" oninput='' onchange='' type="range" min="0" max="1000" step="1" value="0">
Here is the file in its entirety:
<!DOCTYPE html>
<html>
<head>
<title>Size Control to Browser</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style type="text/css" media="screen">
.sliderStyle {
height: 860px;
width: 2%;
-webkit-appearance: slider-vertical;
padding-top: 0px;
margin: 0px;
border: 0px;
}
</style>
<script type="text/javascript">
function start() {
var height = window.innerHeight
|| document.documentElement.clientHeight
|| document.body.clientHeight;
alert('clientHeight: ' + height);
alert("top pad: " + window.getComputedStyle(document.documentElement, null).getPropertyValue('padding-top'));
alert("top margin: " + window.getComputedStyle(document.documentElement, null).getPropertyValue('margin-top'));
document.getElementById("slider").setAttribute('style', "height :" + height + "px");
}
</script>
</head>
<body onload='start()'>
<input id="slider" class="sliderStyle" type="range" min="0" max="1000" step="1" value="0">
</body>
</html>
clientHeight alert confirms that height is changing for different browser sizes
top pad and top margin alerts both return 0px