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);登录后复制 |
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. |
HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号