我以为这很容易。
我有以下HTML
<div>
<div id="child"></div>
</div>
我尝试了几件事
if ($('#child').length){
$('html, body').animate({scrollTop: $(this).parent().offset().top}, 'slow');
}
和
if ($('.success_div').length){
pdiv = $(this).parent();
$('html, body').animate({scrollTop: pdiv.offset().top}, 'slow');
}
错误:TypeError:pdiv.offset(...)未定义
这个怎么样?
if ($('#child').length){
$('body').animate({scrollTop: $('#child').parent().offset().top},'slow');
});
在if语句中调用元素不会选择它,因此$(this)在内不匹配if ($('#child').length){
,因此我$('#child')
在语句内再次调用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句