Js implementation of imitating Sina Weibo back to the top
2、 Return to top function under jQuery
.backToTop {
display: none;
width: 18px;
line - height: one point two ;
padding: 5px zero ;
background - color: # 000 ;
color: #fff;
font - size: 12px;
text - align: center;
position: fixed;
_ position: absolute;
right: 10px;
bottom: 100px;
_ bottom: " auto " ;
cursor: pointer;
opacity: . six ;
filter: Alpha(opacity = sixty );
}
( function () {
var $backToTopTxt = " Back to top " , $backToTopEle = $( ' <div class="backToTop"></div> ' ).appendTo($( " body " ))
.text($backToTopTxt).attr( " title " , $backToTopTxt).click( function () {
$( " html, body " ).animate({ scrollTop: zero }, one hundred and twenty );
}), $backToTopFun = function () {
var st = $(document).scrollTop(), winh = $(window).height();
(st > zero ) ? $backToTopEle.show(): $backToTopEle.hide();
// IE6 Positioning under
if ( ! window. XMLHttpRequest) {
$backToTopEle.css( " top " , st + winh - one hundred and sixty-six );
}
};
$(window).bind( " scroll " , $backToTopFun);
$( function () { $backToTopFun(); });
})();
3、 Implementation of return to top function under MooTools
( function () {
var $backToTopTxt = " Back to top " , $backToTopEle = new Element( " div " , {
" class " : " backToTop " ,
title: $backToTopTxt
}).set( " text " , $backToTopTxt).addEvent( " click " , function () {
var st = document.getScroll().y, speed = st / six ;
var funScroll = function () {
st -= speed;
if (st <= zero ) { st = zero ; }
window.scrollTo( zero , st);
if (st > zero ) { setTimeout(funScroll, twenty ); }
};
funScroll();
}).inject(document.body), $backToTopFun = function () {
var st = document.getScroll().y, winh = window.getSize().y;
(st > zero ) ? $backToTopEle.setStyle( " display " , " block " ): $backToTopEle.setStyle( " display " , " none " );
// Positioning under IE6
if ( ! window. XMLHttpRequest) {
$backToTopEle.setStyle( " top " , st + winh - one hundred and sixty-six );
}
};
window.addEvents({
scroll: $backToTopFun,
domready: $backToTopFun
});
})();
4、 Conclusion