Skip to content

Instantly share code, notes, and snippets.

@wangwen1220
Created March 6, 2014 01:33
Show Gist options
  • Save wangwen1220/9380459 to your computer and use it in GitHub Desktop.
Save wangwen1220/9380459 to your computer and use it in GitHub Desktop.
jq:超简洁代码 jQuery goTop(返回顶部) | jq gotop
// 超简洁代码 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