资源描述:一款页面滚动触发显示进度条插件,自动计算当前页面内容高度,根据当前滚动条所在位置呈现到进百分比度条。
jquery滚动页面顶部百分比进度条插件(共1个文件)
使用方法
$(document).ready(() => {
//add a listener for scroll
$(window).scroll(() => {
//get total height
let docHeight = $(".text-wrapper").height();
//get window height
let winHeight = $(window).height();
//calculate the view port
let viewport = docHeight - winHeight;
//get current scroll position
let scrollPos = $(window).scrollTop();
//get current scroll percent
let scrollPercent = (scrollPos / viewport) * 100;
//add the percent to the top progress bar
$(".indicator").css("width", scrollPercent + "%");
});
});