简体   繁体   English

从页面底部滚动到顶部

[英]scroll from the bottom of the page to the top

i was wondering if is online any jquery plugin that help me to scroll page when i'm at bottom of this. 我想知道是否在线上有任何jquery插件可以帮助我在页面底部滚动页面。

i mean,when i scroll my page to bottom side ,i would like a button that appears and clicking it i can return to the top of page 我的意思是,当我将页面滚动到底部时,我希望出现一个按钮,然后单击它,我可以返回页面顶部

any suggestions? 有什么建议么?

How to tell when you're at the bottom of the page : 如何判断您何时位于页面底部

if (  document.documentElement.clientHeight + 
      $(document).scrollTop() >= document.body.offsetHeight ) { 
    ... 
}

Here's how to scroll to the top of the page: 滚动到页面顶部的方法如下:

$('html, body').animate({scrollTop:0}, 'slow');

Here's how to combine those to and fade a link in to scroll to the top of the page when you hit the bottom of the page (the link only gets reset if you click on it, since that made more sense to me). 这是在您点击页面底部时将它们组合在一起并淡入链接以滚动到页面顶部的方法(仅当您单击该链接时,该链接才会重置,因为这对我来说更有意义)。

This makes use of .animate() . 这利用了.animate() Out of 4 possible arguments, I used 3: properties, duration, and a callback. 在4个可能的参数中,我使用了3个:属性,持续时间和回调。

jsFiddle example jsFiddle示例


$(function() {
    $(window).scroll(function() {
        var totalHeight, currentScroll, visibleHeight;        
          // How far we've scrolled
        currentScroll = $(document).scrollTop();
          // Height of page
        totalHeight = document.body.offsetHeight;
          // Height visible
        visibleHeight = document.documentElement.clientHeight;
          // If visible + scrolled is greater or equal to total
          //   we're at the bottom
        if (visibleHeight + currentScroll >= totalHeight) {
              // Add to top link if it's not there
            if ($("#toTop").length === 0) {
                var toTop = $("<a>");
                toTop.attr("id", "toTop");
                toTop.attr("href", "#");
                toTop.css("display", "none");
                toTop.html("Scroll to Top of Page");
                  // Bind scroll to top of page functionality
                toTop.click(function() {
                      // Use animate w properties, duration and a callback
                    $('html, body').animate({scrollTop:0}, 'slow', function() {
                        $("#toTop").remove();
                    });
                    return false;
                });
                $("body").append(toTop);
                $("#toTop").fadeIn(3000);
            }
        }
    });
});

You can use something like this. 您可以使用类似这样的东西。 It animates the screen to the top of the page. 它将屏幕设置为动画顶部。

$(document).ready(function() {
    $('.backtotop').click(function(){ // requires a class backtotop in the a element.
        $('html, body').animate({scrollTop:0}, 'slow');
    });
    return false;
});

Check this out. 检查这个出来。 Go to the bottom of page and the button is shown. 转到页面底部,显示按钮。 When clicking on it, it scrolls to the page top. 单击它时,它会滚动到页面顶部。

Ant, this is a demo for another plugin . Ant, 是另一个插件的演示。

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

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