在this问题的基础上,我想问一个问题:如何使用类选择器$('.class')
解决同样的问题?
我得到Uncaught TypeError: undefined is not a function
尝试运行时
$('html, body').animate({
scrollTop: $('input.ng-invalid').offset().top
}, 2000);
答案 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);