Skip to content

Instantly share code, notes, and snippets.

@PizzaLiu
Created June 21, 2013 08:18
Show Gist options
  • Save PizzaLiu/5829704 to your computer and use it in GitHub Desktop.
Save PizzaLiu/5829704 to your computer and use it in GitHub Desktop.
html go to top
(function() {
var backToTopTxt = "返回顶部", backToTopEle = $('<div class="backToTop tops"></div>').appendTo($("body"))
.text(backToTopTxt).attr("title", backToTopTxt).click(function() {
$("html, body").animate({ scrollTop: 0 }, 520);
}),
backToTopFun = function() {
var st = $(document).scrollTop(), winh = $(window).height();
(st > 0)? backToTopEle.show(): backToTopEle.hide();
//IE6下的定位
if (!window.XMLHttpRequest) { backToTopEle.css("top", st + winh - 60); }
};
$(window).bind("scroll", backToTopFun);
$(function() { backToTopFun(); });
})();
.backToTop {
display: none;
WIDTH: 45px;
height: 45px;
BOTTOM: 20px;
position: fixed;
_position: absolute;
right: 140px;
bottom: 10px;
_bottom: "auto";
cursor: pointer;
opacity: .6;
filter: Alpha(opacity=60);
text-indent: -9999px;
}
.tops {
background: url('./tops.jpg') no-repeat center center;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment