我稍微修改了您的代码,为您提供了一个我认为您想要的解决方案。与您检查的方式相同
window
对于
scrollTop
和
height
可用于
div
。请注意,为了使此示例正常工作,我将div的高度限制为
100px
。
$('#slide').scroll(function () {
var scroll = $(this).scrollTop();
var scroll_height = $(this).get(0).scrollHeight;
var height = $(this).height ();
var percent = scroll / (scroll_height - height) * 100;
$("#progressbar").text (percent);
});
#progressbar {
border: 1px solid #000;
}
#slide {
height: 100px;
border: 1px solid #000;
overflow-y: scroll;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="progressbar">0</div>
<br><br>
<div type="slideshow" id="slide">
<section>
<header>date </header>
<section>content</section>
</section>
<section>
<header>date </header>
<section>content</section>
</section>
<section>
<header>date </header>
<section>content</section>
</section>
<section>
<header>date </header>
<section>content</section>
</section>
<section>
<header>date </header>
<section>content</section>
</section>
<section>
<header>date </header>
<section>content</section>
</section>
<section>
<header>date </header>
<section>content</section>
</section>
<section>
<header>date </header>
<section>content</section>
</section>
</div>