返回顶部浏览器不兼容

This commit is contained in:
sw 2015-05-07 14:38:02 +08:00
parent f5e87451b9
commit 5f6f937fcb
2 changed files with 48 additions and 11 deletions

View File

@ -60,16 +60,53 @@
);
}
$(window).scroll(function(){
//获取窗口的滚动条的垂直位置
var s = $(window).scrollTop();
//当窗口的滚动条的垂直位置大于页面的最小高度时,让返回顶部元素渐现,否则渐隐
if( s > 600){
$("#gotoTop").fadeIn(100);
}else{
$("#gotoTop").fadeOut(200);
};
});
// $(window).scroll(function(){
// //获取窗口的滚动条的垂直位置
// var s = $(window).scrollTop();
// //当窗口的滚动条的垂直位置大于页面的最小高度时,让返回顶部元素渐现,否则渐隐
// if( s > 600){
// $("#gotoTop").fadeIn(100);
// }else{
// $("#gotoTop").fadeOut(200);
// };
// });
var Sys = {};
var ua = navigator.userAgent.toLowerCase();
var s;
(s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
(s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
(s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
(s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
(s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;
function goTopEx() {
var obj = document.getElementById("goTopBtn");
var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
function getScrollTop() {
var xsun = document.documentElement.scrollTop;
if (Sys.chrome) {
xsun=document.body.scrollTop;
}
return xsun;
}
function setScrollTop(value) {
if (Sys.chrome) {
document.body.scrollTop = value;
}
else {
document.documentElement.scrollTop = value;
}
}
window.onscroll = function () { getScrollTop() > 0 ? obj.style.display = "" : obj.style.display = "none"; };
obj.onclick = function () {
var goTop = setInterval(scrollMove, 10);
function scrollMove() {
setScrollTop(getScrollTop() / 1.1);
if (getScrollTop() < 1) clearInterval(goTop);
}
}
}
</script>
</div>
<div id='bidding_project_list'>

View File

@ -36,7 +36,7 @@
<% end %>
<div class="cl"></div>
<div class="to_top" onclick="javascript:scroll(0,0);" id="gotoTop">
<div class="to_top" onclick="goTopEx();" id="goTopBtn">
返<br/>回<br/>顶<br/>部
</div>
<div class="cl"></div>