foru17
2013-04-07 01:06:39 +08:00
/* 返回顶部*/
var STR_TO_TOP = '返回顶部';
$(function() {
var button = $('<a href="#" id="to-top" title="' + STR_TO_TOP + '">↑</a>').appendTo('body');
$(window).scroll(function() {
if ($(window).scrollTop() > $(window).height()) button.fadeIn(500);
else button.fadeOut(500);
});
button.click(function(e) {
e.preventDefault();
$('html, body').animate({
scrollTop: 0
}, 1000, function() {
window.location.hash = '#';
});
});
});
css文件中设置好a href样式就好了