The Scroll Type of BACK TO TOP

//回顶端 (function(o){ var flag = $.browser.msie && $.browser.version == '6.0', // 是否IE6的标识 windowHeight = $(window).height(), // 窗口可视高度 objHeight = o.height(), // 定位对象高度 $html = $.browser.safari ? $(document.body) : $('html'); if(flag){ // IE6下样式 o.css({ position : 'absolute', right : 0 }) } else { // 非IE6样式 o.css({ position : 'fixed', right : 0, bottom : 0 }) } // 定位函数 function setPos(){ var scrolltop = $html.scrollTop(); if(flag){ //IE6 根据滚动条高度调整位置 o.css({ top : scrolltop + windowHeight - objHeight }) } if(scrolltop == 0){ o.fadeOut(100); } else { o.css('display') == 'none' ? o.fadeIn(300) : null; //判断对象是否显示,防止重复运行 } } // 返回顶部函数 function goTop(){ var t = $html.scrollTop()/4; $html.animate({scrollTop : 0},t) } // 初始化定位 setPos(); $(window).scroll(setPos).resize(setPos); // scroll和resize定位 // 对象绑定返回顶部事件 o.bind('click',goTop); })($('#backTop'));

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.