返回顶部js
backToTop.js:
(function () { var $backToTopEle = $(‘<div class="backToTop"></div>‘).appendTo($("body")) .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(); }); })();
样式设置:
.backToTop { display: none; background:url(../images/go_top.gif); background-repeat:no-repeat; background-position:0px 0px; width:50px; height:50px; color: #fff; font-size: 12px; text-align: center; position: fixed; _position: absolute; right: 2px; bottom: 2px; _bottom: "auto"; cursor: pointer; opacity: .6; filter: Alpha(opacity=60); } .backToTop:hover { background:url(../images/go_top.gif); background-repeat:no-repeat; background-position:0px -100px; }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。