美文网首页
jquery滑到底部、返回顶部

jquery滑到底部、返回顶部

作者: krystal_H | 来源:发表于2019-11-22 17:10 被阅读0次

当页面有滚动条时,显示滑到底部,点击对应按钮到底部

$('.scroll_bottom').click(function () {
  $('html, body').animate({ scrollTop: $(document).height() }, 600)
})

到底部时,点击返回顶部

$('.scroll_top').click(function () {
  $('html, body').animate({ scrollTop: '0px' }, 600)
})

滚动到顶部和底部之间时,显示滑到底部、返回顶部

$(window).bind('scroll', function () {
  var scrollTop = $(this).scrollTop();
  var scrollHeight = $(document).height();
  var windowHeight = $(this).height();
  scrollTop == 0
    ? $('.scroll_tip').show() && $('.scroll_top').hide('fast')
    : $('.scroll_tip').hide() && $('.scroll_top').show('fast')
  if (Math.round(scrollTop + windowHeight) == scrollHeight) {// 滚动到底部
    $('.scroll_bottom').hide('fast')
  } else {
    $('.scroll_bottom').show('fast')
  }
})

相关文章

网友评论

      本文标题:jquery滑到底部、返回顶部

      本文链接:https://www.haomeiwen.com/subject/twyqwctx.html