这jQuery代码使我的页面上的箭头滚动页面。我觉得有一个更好更短的方法来做到这一点。我可以将所有这些代码合并到一个函数中,还是这是唯一的方法吗?
//Functions that make the arrows on the page scroll through the page.
$("#arrow1").click(function() {
$('html, body').animate({
scrollTop: $("#aboutMe").offset().top
}, 1000);
});
$("#arrow2").click(function() {
$('html, body').animate({
scrollTop: $("#skillsPart").offset().top
}, 1000);
});
$("#arrow3").click(function() {
$('html, body').animate({
scrollTop: $("#contactMe").offset().top
}, 1000);
});
$("#arrow4").click(function() {
$('html, body').animate({
scrollTop: $("#topPart").offset().top
}, 1000);
});
根据您的实际标记可以减少它只是一个功能,请包括 – DaniP
烨。当然可以编写干净的代码。 –
你必须使用这些确切的ID吗?我有一个6行解决方案,但我改变了'.offset()'元素的id名称。 –