Created
March 6, 2014 01:33
-
-
Save wangwen1220/9380459 to your computer and use it in GitHub Desktop.
jq:超简洁代码 jQuery goTop(返回顶部) | jq gotop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 超简洁代码 jQuery goTop(返回顶部) | |
$(function() { | |
var $goTop = $('<div id="goTop" style="border:1px solid #444;background:#333;color:#fff;text-align:center;padding:10px 13px 7px 13px;position:fixed;bottom:10px;right:10px;cursor:pointer;display:none;font-family:verdana;font-size:22px;">^</div>').appendTo('body'); | |
$(window).scroll(function() { | |
if ($(this).scrollTop() != 0) { | |
$goTop.fadeIn(); | |
} else { | |
$goTop.fadeOut(); | |
} | |
}); | |
$goTop.click(function() { | |
$('body, html').animate({ | |
scrollTop: 0 | |
}, 800); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment