bricks_add_interaction
Overview
Adds an interaction to a Bricks element, enabling dynamic behavior triggered by user actions or page events. Each interaction consists of a trigger (what initiates it), an action (what happens), and a target (which element is affected). Bricks supports 30+ trigger types including click, hover, scroll, enterView, contentLoaded, form events, WooCommerce events, and AJAX query events.
Interactions are stored in the element’s settings._interactions[] array and are processed by Bricks’ built-in interaction engine on the frontend. Multiple interactions can be stacked on a single element, enabling complex sequential animations and conditional behaviors.
Key Features
When to Use
Trigger scroll-based reveal animations when elements enter the viewport
Show or hide elements on click (toggle menus, accordions, modals)
Chain animations using the animationEnd trigger for sequential effects
Add scroll-to-section behavior to navigation links
Run custom JavaScript functions on specific events
Toggle off-canvas menus or popups based on user interactions
Add storage-based conditional behaviors (show once, remember dismissal)
Element ID must be known (6-character hex ID from bricks_get_page_content)
For target: "custom", the CSS selector must match existing elements
For target: "popup", the popup template must already exist
When NOT to Use
For element visibility based on WordPress data — use bricks_set_element_conditions
For page-level scroll animations — consider AOS library via bricks_load_cdn_library for simpler implementation
Parameters
page_idnumberREQUIREDelement_idstringREQUIREDinteraction.triggerstringREQUIREDclick, hover, mouseOver, mouseLeave, focus, blur, enterView, leaveView, animationEnd, scroll, contentLoaded, mouseleaveWindow, formSubmit, formSuccess, formError, ajaxStart, ajaxEnd, filterOptionEmpty, filterOptionNotEmpty, wooAddedToCart, wooAddingToCart, wooRemovedFromCart, wooUpdateCart, wooCouponApplied, wooCouponRemovedinteraction.actionstringREQUIREDshow, hide, addClass, removeClass, toggleClass, startAnimation, setAttribute, removeAttribute, toggleAttribute, scrollTo, javascript, toggleOffCanvas, clearForm, loadMore, storageAdd, storageRemove, storageCount, togglePopup, openAddress, closeAddressinteraction.targetstringoptionalself Values: self, custom, popupinteraction.targetSelectorstringoptionalinteraction.animationTypestringoptionalinteraction.animationDurationstringoptionalinteraction.classNamestringoptionalinteraction.runOncebooleanoptionalfalseinteraction.jsFunctionstringoptionalcontent_areastringoptionalcontent Values: content, header, footerCode Examples
Warning: Undefined array key "example_output" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 12
Fade-in animation on scroll into view
Add an enterView interaction that triggers a fadeIn animation when a card element scrolls into the viewport.
bricks_add_interaction({
page_id: 42,
element_id: "abc123",
interaction: {
trigger: "enterView",
action: "startAnimation",
target: "self",
animationType: "fadeIn",
animationDuration: "0.6s",
rootMargin: "0px 0px -10% 0px",
runOnce: true
}
})Warning: Undefined array key "example_output" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 12
Toggle class on click with custom target
Add a click interaction on a button that toggles an "active" class on a sibling menu element using a CSS selector.
bricks_add_interaction({
page_id: 42,
element_id: "btn456",
interaction: {
trigger: "click",
action: "toggleClass",
target: "custom",
targetSelector: ".mobile-nav-menu",
className: "is-open"
}
})Common Mistakes
Warning: Undefined array key "fix_description" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 47
Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-includes/kses.php on line 2018
Warning: Undefined array key "wrong_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 48
Warning: Undefined array key "right_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 49
Warning: Undefined array key "fix_description" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 47
Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-includes/kses.php on line 2018
Warning: Undefined array key "wrong_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 48
Warning: Undefined array key "right_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 49
Warning: Undefined array key "fix_description" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 47
Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-includes/kses.php on line 2018
Warning: Undefined array key "wrong_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 48
Warning: Undefined array key "right_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 49
Tips & Warnings
Multiple interactions: You can add multiple interactions to the same element. Each one is appended to the _interactions array. Use bricks_list_interactions to see all interactions on an element.
Animation chaining: Create sequential animations by using animationEnd as the trigger on the next element, referencing the previous interaction’s ID via animationId.
Storage conditions: Use interactionConditions to create smart behaviors like « show banner only if not dismissed » by checking localStorage for a dismissal flag.