簡體   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