Home > Web Front-end > HTML Tutorial > jquery 中scrollTop在Firefox下不起作用_html/css_WEB-ITnose

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

WBOY
Release: 2016-06-24 11:29:41
Original
1186 people have browsed it

 

 

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;}
Copy after login

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);
Copy after login

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( ... );
Copy after login

Working example

The CSS solution would be to set the following styles:

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

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

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template