簡體   English   中英

平滑滾動搜索

[英]Search with smooth scroll

誰能告訴我如何向此腳本添加平滑滾動。

搜索和滾動

JS

    function searchText() {
        console.log($(window).scrollTop($("p:contains('" + $("#search-input").val() + "'):eq(0):last").offset().top));
    }

非常感謝!!

檢查一下: http : //css-tricks.com/snippets/jquery/smooth-scrolling/

使用jQuery的animate()函數

編輯:

只需使用以下功能即可:

function searchText() {
    $('html,body').animate({
        scrollTop: $("p:contains('" + $("#search-input").val() + "'):eq(0):last").offset().top
    }, 1000);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM