简体   繁体   English

平滑滚动搜索

[英]Search with smooth scroll

Can anyone show me how to add a smooth scroll to this script. 谁能告诉我如何向此脚本添加平滑滚动。

search and scroll 搜索和滚动

js JS

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

many thanks!! 非常感谢!!

check this out: http://css-tricks.com/snippets/jquery/smooth-scrolling/ 检查一下: http : //css-tricks.com/snippets/jquery/smooth-scrolling/

using the animate() function of jQuery 使用jQuery的animate()函数

EDIT: 编辑:

just use this function instead: 只需使用以下功能即可:

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