实现点击到底部、顶部、指定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'); 

}

 

posted @ 2018-12-26 21:32  故谣知否  阅读(537)  评论(0编辑  收藏  举报