Skip to content

gfic_lazy_root_margin

Description

This Javascript filter can be used to override the IntersectionObserver: rootMargin option for Image Choices lazy loading

Usage

Applies to all fields.

gform.addFilter( 'gfic_lazy_root_margin', function( margin, formId, currentPage ){
    return margin;
}, 10, 3);

Applies to all fields in a specific form. In this case, form id 5.

gform.addFilter( 'gfic_lazy_root_margin_5', function( margin, formId, currentPage ){
    return margin;
}, 10, 3);

Applies to specific page in a multi-page form. In this case, page 2 in form id 5.

gform.addFilter( 'gfic_lazy_root_margin_5_2', function( margin, formId, currentPage ){
    return margin;
}, 10, 3);

Parameters

  • margin String
    Current margin (defaults to “100px”).
  • formId Number
    The current form id.
  • currentPage Number
    The current page number in a multi-page form, else undefined.

Examples

This example sets the root margin to 50px:

gform.addFilter( 'gfic_lazy_root_margin', function( margin, formId, currentPage ){
    return "50px";
}, 10, 3);

Placement

Your code snippet can be placed in a HTML field on your form (within <script></script> tags), or in a theme custom JavaScript file, or you could use the free Gravity Forms Code Chest addon by our friends at GravityWiz.

Source Code

This filter is located in the imageChoices.InitLazyLoad function in js/gf_image_choices.js.