JQuery Percentage Increases as User Scrolls

本小妞迷上赌 提交于 2019-12-02 11:35:12

Really simple example here

$(window).scroll(function() {
    var startValue = 70; // scrollTop value when to start incrementing
    var stopValue = 300; // scrollTop value when to stop incrementing
    var scrollTop = $(window).scrollTop();
    if (scrollTop > startValue && scrollTop <= stopValue)
        $("#pct").text((((scrollTop-startValue)/(stopValue-startValue))*100).toFixed(0));
    else if (scrollTop <= startValue)
        $("#pct").text(0);
    else if (scrollTop >= stopValue)
        $("#pct").text(100);
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!