Last active
August 29, 2015 13:57
-
-
Save joest67/9479772 to your computer and use it in GitHub Desktop.
This script is used for going to top of the page you are viewing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function(){ | |
var $backToTopTxt = "返回顶部" | |
var $backToTopEle = $('<div class="backToTop"></div>').appendTo($(".site")) | |
.text($backToTopTxt).attr("title", $backToTopTxt).click( | |
function() { | |
$("html, body").animate({ scrollTop: 0 }, 120); | |
}), | |
$backToTopFun = function() { | |
var st = $(document).scrollTop(), winh = $(window).height(); | |
(st > 500)? $backToTopEle.show(): $backToTopEle.hide(); | |
//IE6下的定位 | |
if (!window.XMLHttpRequest) { | |
$backToTopEle.css("top", st + winh - 166); | |
} | |
}; | |
$(window).bind("scroll", $backToTopFun); | |
$(function() { $backToTopFun(); }); | |
}); | |
.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; | |
right: 28%; | |
bottom: 100px; | |
cursor: pointer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment