开发者

jQuery scrollTop function

开发者 https://www.devze.com 2023-03-05 19:16 出处:网络
I have one page where the next page is fired when the user reaches the bottom of the page: $(window).scroll(function(){

I have one page where the next page is fired when the user reaches the bottom of the page:

$(window).scroll(function(){
    if  ($(window).scrollTop() == $(document).height() - $(window).height()){
        next_funtion();
    }
});

However, I want next page to be fired when the user reaches 50% of the page height or 200 px fro开发者_高级运维m the top.


It's basic math. Without it, jQuery ain't gonna help you at all:

$(window).scroll(function() {
  if (($(window).scrollTop() < 200) || ($(window).scrollTop() < $(document).height() / 2)) {
    next_funtion();


You can try this code for ScrollTop Function

$('html,body').animate({

      scrollTop: $('#'+id_name).offset()

    }, "fast");
0

精彩评论

暂无评论...
验证码 换一张
取 消