我有这样的功能:
$.fn.isInViewport = function() {
var elementTop = $(this).offset().top;
var elementBottom = elementTop + $(this).outerHeight();
var viewportTop = $(window).scrollTop();
var viewportBottom = viewportTop + $(window).height();
return elementBottom > viewportTop && elementTop < viewportBottom;
};
我想在onscroll中使用它,并像这样在滚动中启动lottie文件:
$(window).scroll(function () {
var maxFrames = animation1.totalFrames;
if ($('#about-fundamentals').isInViewport()) {
if ( $(document).scrollTop() > Math.round($('#about-fundamentals').offset().top)) {
console.info("bashla");
var scrolledC = $(document).scrollTop() - Math.round($('#about-fundamentals').offset().top);
var heightC = Math.round($('#about-fundamentals').height()-($(window).height()/4));
var ForStop = Math.round(maxFrames * scrolledC / heightC);
animation1.goToAndStop(ForStop,true);
}
if ($(document).scrollTop() > Math.round($('#end-of-about-fundamentals').offset().top)) {
console.info("ghotar");
}
} });
此功能在Chrome中可以正常使用,但在Firefox中存在滞后。有人可以帮助我吗?