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

时间:2015-01-20 10:06:51

标签: javascript jquery scrollto

this问题的基础上,我想问一个问题:如何使用类选择器$('.class')解决同样的问题?

我得到Uncaught TypeError: undefined is not a function

尝试运行时

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

2 个答案:

答案 0 :(得分:2)

试试这个

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

答案 1 :(得分:1)

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

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