当前位置: 移动技术网 > IT编程>开发语言>JavaScript > jquery配合css简单实现返回顶部效果

jquery配合css简单实现返回顶部效果

2018年12月09日  | 移动技术网IT编程  | 我要评论

代码如下:


.backtotop {
display: none;
width: 18px;
line-height: 1.2;
padding: 5px 0;
background-color: #000;
color: #fff;
font-size: 12px;
text-align: center;
position: fixed;
_position: absolute;
right: 10px;
bottom: 100px;
_bottom: "auto";
cursor: pointer;
opacity: .6;
filter: alpha(opacity=60);
}


jquery代码

. 代码如下:


(function() {
var $backtotoptxt = "返回顶部", $backtotopele = $('<p class="backtotop"></p>').appendto($("body"))
.text($backtotoptxt).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(); }); })();:

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网