页面刷新回到顶部"/>
html页面刷新回到顶部
回到顶部jquery实现代码,如何实现回到页面顶部功能?
计算机天堂 www.jsjtt.go2top {
background: url(".png") no-repeat scroll left top transparent;
bottom: 15px;
color: #444444;
display: none;
height: 50px;
position: fixed;
right: 15px;
text-align: center;
width: 50px;
cursor: pointer;
}
.go2top:hover {
background-position: -50px top;
}
$(document).ready(function() {
var backToTopTxt = "返回顶部", backToTopEle = $('
.attr("title", backToTopTxt).click(function() {
$("html, body").animate({ scrollTop: 0 }, 120);
}), $backToTopFun = function() {
//获取滚动条所在页面的高度
var st = $(document).scrollTop(), winh = $(window).height();
(st > 0)? backToTopEle.show(): backToTopEle.hide();
//IE6下的定位
if (!window.XMLHttpRequest) {
backToTopEle.css("top", st + winh - 166);
}
};
//绑定滚动条滚动事件
$(window).bind("scroll", $backToTopFun);
$(function() { $backToTopFun(); });
});
更多推荐
html页面刷新回到顶部
发布评论