仅当类被隐藏或表单打开时才滚动到该项目。查看 jsfiddle。
http://jsfiddle.net/jdE2v/93/ 你能快速看一下吗?这是我能到达的最接近的地方。
// toggle and hide all but the form u want to edit
$('[class^="toggle-new-form"]').click(function() {
var el = $(this).parent().next();
$('[class^="new-form"]').not(el).addClass('hidden');
el.toggleClass("hidden");
});
// scroll down to view to see all payment Options
$('.scroll-payment-options').click(function() {
$('body,html').animate({
scrollTop: $(".scroll-payment-options").offset().top
}, 800);
});
最佳答案
使用 hasClass
检查元素是否有隐藏类,如下所示:
// toggle and hide all but the form u want to edit
$('[class^="toggle-new-form"]').click(function() {
var el = $(this).parent().next();
$('[class^="new-form"]').not(el).addClass('hidden');
el.toggleClass("hidden");
});
// scroll down to view to see all payment Options
$('.scroll-payment-options').click(function() {
if(!($(this).parent().find('[class^="new-form"]').hasClass('hidden'))){
$('body,html').animate({
scrollTop: $(".scroll-payment-options").offset().top
}, 800);
}
});
关于javascript如果类被隐藏然后滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40309768/