为什么在页面的指定区域滚动滚动开始抽签。为什么“滚动滚动”事件不会在firefox中触发,但在chrome中可以正常工作?

时间:2018-07-29 06:54:43

标签: javascript jquery lottie bodymovin

我有这样的功能:

    $.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中存在滞后。有人可以帮助我吗?

0 个答案:

没有答案