简体   繁体   English

如何向下滚动像向上滚动一样,在向下滚动中我没有页面高度

[英]How to scroll down like scroll up ,In scroll down I'm not getting page height

I'm unable to scroll down at the bottom... 我无法向下滚动底部...

At there above code is working fine for top but for bottom we don't know the height of page.Then it's creating problem for going end of the page. 上面的代码对于顶部来说工作正常,但对于底部我们不知道页面的高度,这给页面末尾带来了问题。 please suggest me...Thanks 请建议我...谢谢

$('.scrollToDown').fadeIn();
$(window).scroll(function(){
    if ($(this).scrollTop() > 0) {
        $('.scrollToTop').fadeIn();
        $('.scrollToDown').fadeOut();
    } else {
        $('.scrollToTop').fadeOut();
        $('.scrollToDown').fadeIn();
    }
});
$('.scrollToTop').click(function(){
    $('html, body').animate({scrollTop : 0},700);
    return false;
});
$('.scrollToDown').click(function(){
    $('html, body').animate({scrollTop : 5110},1000);
    return false;
});

You can use $(document).height() 您可以使用$(document).height()

try this 尝试这个

$('.scrollToDown').fadeIn();
$(window).scroll(function(){
    if ($(this).scrollTop() > 0) {
        $('.scrollToTop').fadeIn();
        $('.scrollToDown').fadeOut();
    } else {
        $('.scrollToTop').fadeOut();
        $('.scrollToDown').fadeIn();
    }
});
$('.scrollToTop').click(function(){
    $('html, body').animate({scrollTop : 0},700);
    return false;
});
$('.scrollToDown').click(function(){
    $('html, body').animate({scrollTop : $(document).height()},1000);
    return false;
});

You can just animate to scroll down the page by animating the scrollTop property, no plugin required, like this: 您可以通过设置scrollTop属性的动画来向下滚动页面,无需插件,如下所示:

$(window).load(function() {
  $("html, body").animate({ scrollTop: $(document).height() }, 1000);
});

Note the use of window.onload (when images are loaded...which occupy height) rather than document.ready. 请注意,使用window.onload(加载图像时...占据高度)而不是document.ready。

To be technically correct, you need to subtract the window's height, but the above works: 为了技术上正确,您需要减去窗口的高度,但是上面的方法有效:

$("html, body").animate({ scrollTop: $(document).height()-$(window).height() });

To scroll to a particular ID, use its .scrollTop(), like this: 要滚动到特定的ID,请使用其.scrollTop(),如下所示:

$("html, body").animate({ scrollTop: $("#myID").scrollTop() }, 1000);

The value that you should scroll to is the height of the page minus the height of the window: 您应该滚动到的值是页面的高度减去窗口的高度:

$('.scrollToDown').click(function(){
    var h = $(document).height() - $(window).height();
    if (h > 0) {
        $('html, body').animate({scrollTop : h},1000);
    }
    return false;
});

Demo: http://jsfiddle.net/Guffa/cnfn8ayr/ 演示: http//jsfiddle.net/Guffa/cnfn8ayr/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM