<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<style>
.swkc_scroll{
position: fixed;
bottom: 50px;
right: 30px;
width: 70px;
height: 70px;
background:#ddd;
text-align: center;
cursor: pointer;
display: none;
}
#box{
height: 2180px;
background: red;
width: 100px;
}
</style>
</head>
<body>
<div class="swkc_scroll">
<p>TOP</p>
</div>
<div id="box">
</div>
</body>
<script>
$(function(){
$(window).scroll(function () {
if ($(this).scrollTop() > 300) {
$(".swkc_scroll").fadeIn();
} else {
$(".swkc_scroll").fadeOut();
}
});
$(".swkc_scroll").click(function () {
if ($(window).scrollTop() > 0) {
$("html,body").stop().animate({ scrollTop: 0 }, 600);
}
});
})
</script>
</html>