我刚刚发现我的脚本在 Chrome 中运行良好,但在 FireFox 中运行不佳 - 我不明白为什么。
这是正在开发的网站:www.fireflycovers.com
当单击圆形绿色按钮之一时,应执行该脚本。 (将窗口滚动到下一个容器)
脚本目前看起来像这样:
$('.scroll').css('display' , 'block');
$('.scroll').on('click', function(e) {
var container = $(this).parent();
// Scans if last container in group
while (document != container[0] &&
container.find('~.col, ~:has(.col)').length == 0) {
// If so, search siblings of parent instead
var container = container.parent(),
nextdiv = container.nextAll('.col, :has(.col)').first();
}
// Back to first .col (when no next .col)
if (nextdiv.length == 0) {
nextdiv = $(document).find('.col:first')
};
// Animates scrolling to new position
$('body').animate({scrollTop:nextdiv.offset().top}, 1000);
return false;
});
});
最佳答案
您尝试过调试吗?例如,在整个方法中放置 console.log
语句来查看特定时间事物的值并观察它的执行?无论如何,使用这个有帮助吗?
$('body,html').animate({scrollTop:nextdiv.offset().top}, 1000);
验证自Animate scrollTop not working in firefox
您需要 html
,因为 Firefox 在溢出
方面的行为有所不同。
关于javascript - Jquery/Javascript 无法在 Firefox 上运行。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13617261/