html页面刷新回到顶部

编程入门 行业动态 更新时间:2024-10-04 11:22:29

html<a href=https://www.elefans.com/category/jswz/34/1771336.html style=页面刷新回到顶部"/>

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页面刷新回到顶部

本文发布于:2024-02-13 22:56:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1761087.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:页面   html

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!