Tagged: avia, javascript, runtime
Hi,
I want to add Avia-Elements on runtime, especially new Color Section with parallax. I can add those elements without a problem with something like this:
const section = document.createElement('div');
section.id = 'av_section_wp' + i;
section.classList.add('avia-section', 'alternate_color', 'avia-section-default', 'avia-no-border-styling', 'avia-full-stretch', 'av-parallax-section', 'avia-bg-style-parallax', 'av-minimum-height', 'av-minimum-height-100', 'av-height-100', 'container_wrap', 'fullscreen');
section.dataset.sectionBgRepeat = 'stretch';
section.dataset.av_minimum_height_pc = '100';
section.dataset.av_min_height_opt = '100';
const sectionParallax = document.createElement('div');
sectionParallax.classList.add('av-parallax', 'active-parallax', 'enabled-parallax');
sectionParallax.dataset.aviaParallaxRation = '0.3';
...
But this new section doesn’t have a parallax effect. It seems like it is isn’t registered in the JavaScript module for parallax. Is there a way to register those elements or generally speaking, is there a better way to add Avia elements on runtime?
Best,
Henning
Hey henningtillmann,
Thank you for the inquiry.
We haven’t tried this before but it should work. Just make sure that script is loaded before the avia-parallax-support script or the avia-snippet-parallax.js file.
Example:
function ava_enqueue_additional_script_before_parallax() {
// Enqueue your new script with a dependency on 'avia-default' to make sure it loads before 'avia-parallax-support'
wp_enqueue_script( 'your-new-script', "{$template_url}/js/your-new-script{$min_js}.js", array( 'avia-default' ), $vn, true );
}
add_action( 'wp_enqueue_scripts', 'ava_enqueue_additional_script_before_parallax', 20 );
Let us know of the result.
Best regards,
Ismael