JQ怎样返回顶部代码

<div id="toTop" class="hidden-xs" style="display: none;">返回顶部</div>

<style>
 #toTop {position: fixed;right: 20px;bottom: 25px;zindex: 12;display: none;width: 47px;height: 47px;background:red;text-align: center;text-indent: -9999px;cursor: pointer;}
</style>
<script>
$(window).scroll(function() {

if ($(this).scrollTop() != 0) {

 $("#toTop").fadeIn()

} else {

 $("#toTop").fadeOut()

 }

 });

$("#toTop").click(function() {

$("body,html").animate({

 scrollTop: 0

 }, 800)

 })
</script>

 

posted @ 2016-05-23 14:13  八路逆袭寡妇村  阅读(136)  评论(0)    收藏  举报
www.zxzidian.com