如何使用类选择器使用 Jquery ScrollTo() 将页面滚动到元素

How to scroll page to the element with Jquery ScrollTo() using class selector?

本文关键字:滚动 元素 ScrollTo 何使用 选择器 Jquery      更新时间:2023-09-26
基于

这个问题,我想问一个问题:如何使用类选择器$('.class')解决相同的问题?

我得到Uncaught TypeError: undefined is not a function

尝试运行此内容时

$('html, body').animate({
    scrollTop: $('input.ng-invalid').offset().top
}, 2000);

试试这个

var sc = $('div[class="classname"]').offset().top;
        $('body,html').animate({
            scrollTop: (sc - 30)
        },
        'slow');

我不确定,但这就是你想要的? http://jsfiddle.net/65q6xo95/1/

$('html, body').animate({
    scrollTop: $('.ng-invalid:first').offset().top
}, 2000);