<div id="hqestop"></div>
<div class="backtop">
<!-- onfocus="this.blur();去掉点击a标签时的虚线 -->
<a href="#hqestop" target="_self" onfocus="this.blur();">
<button class="btnbacktop" type="回到顶部" onfocus="this.blur();">
<i class="fa fa-caret-up"></i>
</button>
</a>
</div>
<script>
$(document).ready(function(){
$(".backtop").hide();
$(function () {
//检测屏幕高度
var height=$(window).height();
//scroll() 方法为滚动事件
$(window).scroll(function(){
if ($(window).scrollTop()>height){
$(".backtop").fadeIn(500);
}else{
$(".backtop").fadeOut(500);
}
});
$(".backtop").click(function(){
$('body,html').animate({scrollTop:0},100);
return false;
});
});
});
</script>
复制代码
转载于:https://juejin.im/post/5a39fcf86fb9a0451d419de9