动画滚动顶部无法在Firefox中工作这个函数工作得很好。它将身体滚动到所需容器的偏移量。function scrolear(destino){
var stop = $(destino).offset().top;
var delay = 1000;
$('body').animate({scrollTop: stop}, delay);
return false;}但在Firefox中并非如此。为什么?为了在接受的答案中处理de Double触发器,我建议在动画之前停止元素:$('body,html').stop(true,true).animate({scrollTop: stop}, delay);
3 回答
慕妹3146593
TA贡献1820条经验 获得超9个赞
html
$('body,html').animate( ... );
工作实例
html { overflow: hidden; height: 100%; }body { overflow: auto; height: 100%; }
更新
scrollTop
function runOnce(fn) { var count = 0; return function() { if(++count == 1) fn.apply(this, arguments); };};$('body, html').animate({ scrollTop: stop }, delay, runOnce(function() { console.log('scroll complete');}));
幕布斯6054654
TA贡献1876条经验 获得超7个赞
$('html, body') .animate({ scrollTop: 100 }) .promise() .then(function(){ // callback code here })});
// Note that the DOM needs to be loaded first, // or else document.body will be undefinedfunction getScrollTopElement() { // if missing doctype (quirks mode) then will always use 'body' if ( document.compatMode !== 'CSS1Compat' ) return 'body'; // if there's a doctype (and your page should) // most browsers will support the scrollTop property on EITHER html OR body // we'll have to do a quick test to detect which one... var html = document.documentElement; var body = document.body; // get our starting position. // pageYOffset works for all browsers except IE8 and below var startingY = window.pageYOffset || body.scrollTop || html.scrollTop; // scroll the window down by 1px (scrollTo works in all browsers) var newY = startingY + 1; window.scrollTo(0, newY); // And check which property changed // FF and IE use only html. Safari uses only body. // Chrome has values for both, but says // body.scrollTop is deprecated when in Strict mode., // so let's check for html first. var element = ( html.scrollTop === newY ) ? 'html' : 'body'; // now reset back to the starting position window.scrollTo(0, startingY); return element;}// store the element selector name in a global var - // we'll use this as the selector for our page scrolling animation.scrollTopElement = getScrollTopElement();
$(scrollTopElement).animate({ scrollTop: 100 }, 500, function() { // normal callback});
牧羊人nacy
TA贡献1862条经验 获得超7个赞
$('body,html').animate({scrollTop: 50}, 500);
body { height: 100%};
auto
100%
- 3 回答
- 0 关注
- 373 浏览
添加回答
举报
0/150
提交
取消