当html页面与不需要屏幕视图滚动条的尺寸相同时,当你继续在网页中添加元素(参考我的代码)时,页面的长度大于视图滚动条出现的长度,并且随着网页长度的增加而变化,我已经看过如何使用滚动顶( .but )等方法找到滚动位置,我从来不知道它是如何出现的。
简单虚码
<html>
<head>
<style>
.box1{
height:50%;
width:100%;
border:1px solid black;
}
.box2{
height:50%;
width:100%;
border :1px solid black;
}
</style>
</head>
<body>
<div class="box1">
</div>
<div class="box2">
</div>
</body>
</html>页长增加
<html>
<head>
<style>
.box1{
height:50%;
width:100%;
border:1px solid black;
}
.box2{
height:50%;
width:100%;
border :1px solid black;
}
.box3{
height:50%;
width:100%;
border:1px solid black;
}
</style>
</head>
<body>
<div class="box1">
</div>
<div class="box2">
</div>
<div class="box3">
</div>
</body>
</html>I am curious of how the browser calculates scroll bar length(in %) according to the length of the page and how the scroll bar length increases/decreases based on the webpage。是否有任何数学公式(不确定),比如计算整个页面的长度(元素的长度)-(浏览器的视图维)/(通过某个未知变量)。
发布于 2017-03-24 12:03:10
浏览器获取屏幕的高度(例如1000 of ),并计算文档总高度的百分比。如果文档高度为3000 is,则结果为33%。因此,滚动条的高度必须是屏幕高度的33%,以像素为单位是333 in。
发布于 2017-03-24 12:05:43
可能是这样的
var heightIs = parseInt( $(window).height() / ( $("body").height() / $(window).height() ) );你得到身体高度和窗口高度之间的比率,然后用这个比率除以窗口高度。
https://stackoverflow.com/questions/42998671
复制相似问题