📜  滚动到 div js - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:41.792000             🧑  作者: Mango

代码示例2
//scroll to id
    var $root = $('html, body');
    $('a[href^="#"]').click(function () {
        var href = $.attr(this, 'href');
        $root.animate({
            scrollTop: $(href).offset().top
        }, 500, function () {
            window.location.hash = href;
        });

        return false;
    });