首页 > Web开发 > 详细

【转】jquery 中scrollTop在Firefox下不起作用

时间:2016-01-13 19:22:01      阅读:225      评论:0      收藏:0      [点我收藏+]

原文链接:http://stackoverflow.com/questions/8149155/animate-scrolltop-not-working-in-firefox

 

 

技术分享

This function works fine. It scrolls the body to a desired container‘s offset

function scrolear(destino){
    var stop = $(destino).offset().top;
    var delay = 1000;
    $(‘body‘).animate({scrollTop: stop}, delay);
    return false;
}

But not in Firefox. Why?

-EDIT-

To handle de double trigger in the acepted answer, I suggest stoping the element before the animation:

$(‘body,html‘).stop(true,true).animate({scrollTop: stop}, delay);

up vote 240 down vote accepted

Firefox places the overflow at the html level, unless specifically styled to behave differently.

To get it to work in Firefox, use

$(‘body,html‘).animate( ... );

Working example

The CSS solution would be to set the following styles:

html { overflow: hidden; height: 100%; }
body { overflow: auto; height: 100%; }

I would assume that the JS solution would be least invasive.

【转】jquery 中scrollTop在Firefox下不起作用

原文:http://www.cnblogs.com/wlf-919874006/p/5127978.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!