>  기사  >  웹 프론트엔드  >  jquery 中scrollTop在Firefox下不起作用_html/css_WEB-ITnose

jquery 中scrollTop在Firefox下不起作用_html/css_WEB-ITnose

WBOY
WBOY원래의
2016-06-24 11:29:411142검색

 

 

Animate scrollTop not working in firefox

up vote 115 down vote favorite

21

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);

10 Answers

active oldest votes

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.

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.