-Asagi 随笔-
通过判断浏览器的高度,来显示或者隐藏TOP 按钮。
body{
margin: 0;
padding: 0;
height: 2000px;
}
.box{
width: 30px;
height: 30px;
opacity: 0;
text-align: center;
line-height: 30px;
position: fixed;
right: 50px;
bottom: 80px;
color: white;
background-color: red;
}
.asagi{
position: fixed;
bottom: 20px;
left: 10px;
}
.box_m{
opacity: .5;
}
.box:hover{
opacity: .8;
}
$(window).scroll(function () {
if ($(window).scrollTop() > 200)
{
$("#box").addClass('box_m');
}
else{
$("#box").removeClass('box_m');
}})