繁体   English   中英

按钮,通过单击按钮一直滚动到顶部

[英]button to scroll all the way to the top with click of button

我有这个javascript,因此当用户在页面上滚动时,侧面会有一个小图标,它将一直滚动到整个页面上,而不是手动滚动。 该按钮显示正常,但是当我单击它时,并不会一直到顶部。

html

<a href="#" class="scrollup">Scroll</a>

脚本

$(document).ready(function () {

        $('#main').scroll(function () {
            if ($(this).scrollTop() > 100) {
                $('.scrollup').fadeIn();
            } else {
                $('.scrollup').fadeOut();
            }
        });

        $('.scrollup').click(function () {
            $("html, body, main_container, main").animate({ scrollTop: 0 }, 600);
            return false;
        });

    });

问题是在选择,你缺少要么# id选择或. 类选择器,对我来说似乎是id:

改变这个:

$("html, body, main_container, main")

为此,看看是否有帮助:

$("html, body, #main_container, #main")
//-------------^----------------^--------these selector notations

暂无
暂无

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

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