您可以调用该$(this).scrollTop()
函数并定义 scrollTop 事件
$(this).scrollTop(function(){
//your code to do both tasks
)};
希望能帮助到你 :)
更新:
function slideonlyone(thechosenone) {
$('.newboxes2').each(function(index) {
if (this.id == thechosenone) {
if($(this).is('.active') )
$(this).removeClass('active').slideUp(600);
else
$(this).addClass('active').slideDown(200);
}
else
$(this).removeClass('active').slideUp(600);
if($(this).is('.active') )
jQuery(this).parent('.grid_4').children().find('img.small').attr('src', '/wp-content/themes/boilerplate/images/image_corner_btn_onstate.png');
else
jQuery(this).parent('.grid_4').children().find('img.small').attr('src', '/wp-content/themes/boilerplate/images/image_corner_btn_offstate.png');
});
}
$('#box1 h2').click(function () {
$('html, body').animate({
scrollTop: $('#box2').offset().top}, 'slow');
slideonlyone(thechosenone);
return false;
});
$('#box2 h2').click(function () {
$('html, body').animate({
scrollTop: $('#box1').offset().top}, 'slow');
slideonlyone(thechosenone);
return false;
});