【轉】jquery 中scrollTop在Firefox下不起做用

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

 

 

This function works fine. It scrolls the body to a desired container's offsetless

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

But not in Firefox. Why?ide

-EDIT-post

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

$('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.spa

To get it to work in Firefox, use.net

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

Working examplefirefox

The CSS solution would be to set the following styles:code

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

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

相關文章
相關標籤/搜索