简体   繁体   English

如何使用jQuery创建动画滚动到向下按钮

[英]How To Create An Animated Scroll To Down Button With jQuery

This script for scroll to top, how can i change to scroll down. 此脚本滚动到顶部,我如何更改为向下滚动。

This is my script: 这是我的脚本:

$(document).ready(function(){

//Check to see if the window is top if not then display button
$(window).scroll(function(){
    if ($(this).scrollTop() > 100) {
        $('.scrollToTop').fadeIn();
    } else {
        $('.scrollToTop').fadeOut();
    }
});

//Click event to scroll to top
$('.scrollToTop').click(function(){
    $('html, body').animate({scrollTop : 0},800);
    return false;
});
});

这将使用jQuery将窗口动画化到页面底部

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

You can try this 你可以试试这个

$("#DIV1").animate({
    scrollTop: $('#DIV2').offset().top - $("#DIV1").offset().top + $("#DIV1").scrollTop()-80
},800);

Here DIV2 is the DIV that u want to scroll and DIV1 is where u want to scroll . DIV2是您要滚动的DIV,DIV1是您要滚动的位置。

By changing value 80 to different values u can scroll at any position 通过将值80更改为不同的值,您可以在任何位置滚动

To scroll up or down increase or decrease value.. 上下滚动增加或减少值。

Hope works for u 希望为你工作

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

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