{"id":2225,"date":"2021-01-20T10:30:00","date_gmt":"2021-01-20T10:30:00","guid":{"rendered":"https:\/\/www.gmitropapas.com\/?post_type=knowledgebase&p=2225"},"modified":"2024-02-28T18:53:15","modified_gmt":"2024-02-28T18:53:15","slug":"scrolling-animation-effects-in-generateblocks-pro","status":"publish","type":"knowledgebase","link":"https:\/\/www.gmitropapas.com\/generatepress-tips-and-tricks\/generateblocks\/scrolling-animation-effects-in-generateblocks-pro\/","title":{"rendered":"Scrolling animation effects in GenerateBlocks Pro"},"content":{"rendered":"
The new GenerateBlocks Pro<\/a> plugin is now available for purchase and it’s awesome! One of the new features added is the ability to add your own custom attributes<\/strong> to a GenerateBlocks container<\/strong>. Amongst other things, this gives us the ability to integrate various JavaScript libraries<\/strong> that make use of those custom attributes. One of those libraries is a very lightweight scrolling library called Sal.js<\/a>.<\/p>\n\n\n\n Sal.js<\/strong> (Scroll Animation Library)<\/a> is a performance-focused, lightweight (less than 2.8 kb) scroll animation library, written in vanilla JavaScript<\/strong> with no dependencies! It was created to provide a performant and lightweight solution for animating elements on scroll. It’s based on the Intersection Observer<\/strong>, which gives an amazing performance in terms of checking the element’s presence in the viewport.<\/p>\n\n\n\n To download the library, head over to the GitHub repository<\/a>, select the green In my case, I am going to use the library for the Create Advanced<\/a> homepage of my agency website. The following code added to functions.php<\/strong> will enqueue the files only for the homepage. <\/p>\n\n\n\n To include the scripts for the whole website just remove the Finally, I entered the following into the sal-init.js<\/strong> to initialize the script and also disable the scrolling animation effect for mobile devices.<\/p>\n\n\n\nCode<\/code> button and from the dropdown that appears select Download ZIP<\/strong>. Once the package is downloaded, create a child theme and add an extra folder inside it called sal (or any name you want). Now, extract the zip file you downloaded into a location on your computer, copy sal.css<\/strong> and sal.js<\/strong> files located inside sal-master->dist<\/strong> folder and paste those files inside the sal folder you created in your child theme directory. Finally, create another js file named sal-init.js<\/strong> (or any name you want). We are going to use that file as our initialization script<\/strong>.<\/p>\n\n\n\n
function gm_enqueue_sal_scripts() {\n if( is_front_page() )\n {\n wp_enqueue_style( 'sal', get_stylesheet_directory_uri() . '\/sal\/sal.css' );\n\t\twp_enqueue_script( 'sal', get_stylesheet_directory_uri() . '\/sal\/sal.js', array(), false, true );\n\t\twp_enqueue_script( 'sal-init', get_stylesheet_directory_uri() . '\/sal\/sal-init.js', null, null, true );\n }\n}\n\nadd_action( 'wp_enqueue_scripts', 'gm_enqueue_sal_scripts' );<\/pre>\n\n\n\n
is_front_page()<\/a><\/code> conditional.<\/p>\n\n\n\n
function gm_enqueue_sal_scripts() {\n\n wp_enqueue_style( 'sal', get_stylesheet_directory_uri() . '\/sal\/sal.css' );\n wp_enqueue_script( 'sal', get_stylesheet_directory_uri() . '\/sal\/sal.js', array(), false, true );\n wp_enqueue_script( 'sal-init', get_stylesheet_directory_uri() . '\/sal\/sal-init.js', null, null, true );\n\n}\n\nadd_action( 'wp_enqueue_scripts', 'gm_enqueue_sal_scripts' );<\/pre>\n\n\n\n
const animation = sal();\n\nconst switchAnimations = () => {\n if (window.innerWidth < 768) {\n animation.reset();\n animation.disable();\n } else {\n animation.reset();\n animation.enable();\n }\n};\n\nswitchAnimations();\nwindow.addEventListener('resize', switchAnimations);<\/pre>\n\n\n\n