Facetwp scroll to top only on pager facet interaction

<?php

/** Adds script to header 
 ** Scroll to top of page only on pager facet interaction
 ** For more info see:
 ** https://facetwp.com/help-center/facets/facet-types/pager/#how-to-add-pagination-scrolling
 **/

add_action( 'wp_head', function() { ?>

    <script>
        (function($) {
            $(document).on('facetwp-refresh', function() {
                if ( FWP.soft_refresh == true ) {
                    FWP.enable_scroll = true;
                } else {
                    FWP.enable_scroll = false;
                }
            });
            $(document).on('facetwp-loaded', function() {
                if ( FWP.enable_scroll == true ) {
                    $('html, body').animate({ scrollTop: 0 }, 500);
                }
            });
        })(jQuery);
    </script>

<?php } );