实现点击到底部、顶部、指定div功能

顶部:

$(".back_top").click(function () {
  scrollTo(0, 0);
});

function goTop() {

  $('html, body').animate({scrollTop:0}, 'slow');

}

底部:

$(".back_bottom").click(function () {
  $('html,body').animate({ scrollTop: document.documentElement.scrollHeight }, 800);
});

function goBottom(){

  window.scrollTo(0, document.documentElement.scrollHeight-document.documentElement.clientHeight);

}

指定div:

function goDiv(div) {

  var a = $("#"+div).offset().top;

  $("html,body").animate({scrollTop:a}, 'slow'); 

}

猜你喜欢

转载自www.cnblogs.com/simplemoe/p/10181967.html
今日推荐