CSS code
. 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 );
}
JS Code
(Function (){
Var $ backToTopTxt = "Back to Top", $ backToTopEle = $ ('<div class = "backToTop"> </div>'). appendTo ($ ("body "))
. Text ($ backtoptxt). attr ("title", $ backtoptxt). click (function (){
$ ("Html, body"). animate ({scrollTop: 0}, 120 );
}), $ Backtopfun = function (){
Var st = $ (document). scrollTop (), winh = $ (window). height ();
(St> 0 )? $ BackToTopEle. show (): $ backToTopEle. hide ();
// Positioning in IE6
If (! Window. XMLHttpRequest ){
$BackToTopEle.css ("top", st + winh-166 );
}
};
$ (Window). bind ("scroll", $ backToTopFun );
$ (Function () {$ backtopfun ();});
})();
From AnsonChen