回到顶部

实现一个回到顶部的按钮:

第一屏不显示,从第二屏开始,从右下方向上逐步滚出;

回到第一屏,“回到顶部”按钮由上往下,逐步隐藏。
回到顶部GIF

html:

<div class="backtotop"><img src="~/Images/回顶部@2x.png" /></div>

CSS:

.backtotop {
  position: fixed;
  z-index: 999;
  right: 0.4rem;
  bottom: -1.3333333rem;
  width: 1.3333333rem;
  height: 1.3333333rem;
  transition: all 0.4s ease-in-out;
}
.backtotop.show {
  bottom: 0.4rem;
}

js:

backtotopBtnShow: function () {
    var that = this;
    var scrollTop = getScrollTop();
    if (scrollTop > window.innerHeight) {
        $('.backtotop').addClass('show');
    } else {
        $('.backtotop').removeClass('show');
    }
}

热评文章