用jQuery实现回到顶部

来源:互联网 发布:英国大学精算 知乎 编辑:程序博客网 时间:2024/06/04 19:31

jsp代码

<div class="go-top" title="返回顶部"><img src="img/go_top.png"/></div>

js代码


$(function(){// 回到顶部$(window).scroll(function() {if ($(window).scrollTop() > 0)$(".go-top").show();else$(".go-top").hide();});$(".go-top").click(function() {$("html, body").animate({scrollTop : 0}, 1000);});})

css代码

.go-top{display: none;position: fixed;top:80%;left: 90%;width: 60px;height: 60px;cursor: pointer;background: white;}.go-top img{width: 60px;height: 60px;}.go-top:hover{background-color: gray;opacity: 1;filter: alpha(opacity=100);}

效果


原创粉丝点击