100分扒一个回到顶部JS
http://www.cnblogs.com/lhb25/
那个很不错。
[解决办法]
function backTop(){ $(function(){ // hide #back-top first $("#back-top").hide(); // fade in #back-top $(function () { $(window).scroll(function () { if ($(this).scrollTop() > 500) { $('#back-top').fadeIn(); } else { $('#back-top').fadeOut(); } }); // scroll body to 0px on click $('#back-top a').click(function () { $('body,html').animate({ scrollTop: 0 }, 800); return false; }); }); });}backTop();
[解决办法]
function backTop(){
$(function(){
// hide #back-top first
$("#back-top").hide();
// fade in #back-top
$(function () {
$(window).scroll(function () {
if ($(this).scrollTop() > 500) {
$('#back-top').fadeIn();
} else {
$('#back-top').fadeOut();
}
});
// scroll body to 0px on click
$('#back-top a').click(function () {
$('body,html').animate({
scrollTop: 0
}, 800);
return false;
});
});
});
}
backTop();
[解决办法]
没看见楼主贴的链接的gotop
封装了个
<!DOCTYPE HTML><html> <head> <meta charset="gb2312" /> <title></title> </head> <body style="height:2000px;"> <script> ;(function(w, d){ var o = d.createElement('div'); d.getElementsByTagName('body')[0].appendChild(o); o.style.cssText = 'display:none; position:absolute; top:0; right:10px; padding:0 4px 4px; width:12px; border:1px solid #6eaae5; color:#6eaae5; font-size:12px; cursor:pointer;'; o.innerHTML = '<div style="margin:0 0 4px 0; width:0; height:0; overflow:hidden; border:6px dashed transparent; border-bottom-style:solid; border-bottom-color:#6eaae5;"></div>回顶部'; o.onclick = function(){ w.scrollTo(0,0); } w.onscroll = function(){ var sTop = d.documentElement.scrollTop || d.body.scrollTop; sTop ? (o.style.display = 'block', o.style.top = sTop + 200 + 'px') : o.style.display = 'none'; } })(window, document); </script> </body></html>
[解决办法]