-
AuthorPosts
-
March 11, 2016 at 2:00 am #833289
smartsimulationParticipantHi,
I would like to add a script for scroll-controlled animations such as seen here: https://ihatetomatoes.net/demos/one-page-scroll-animations/
Would just like to have some pointers on whether this type of script is possible to integrate within X theme. It is composed of multiple js scripts with their own folder structure.
And then the on-page integration, I am in doubt whether this is done via code snippet or raw content?
Would appreciate some pointers.
Many thanks,
March 11, 2016 at 2:30 am #833308
Rue NelModeratorHello There,
Thanks for writing in! Because this requires a template change, I’d advise that you setup a child theme. This allows you to make code changes that won’t be overwritten when an X update is released. After your child theme is setup, please review how we recommend making template changes in Customization Best Practices.
Once you already have your child theme active and ready, please insert this following code in your child theme’s functions.php file so that you can add a custom JS to the site.
// Add custom JS scripts // ============================================================================= function load_custom_js() { wp_enqueue_style( 'custom-js', 'get_template_directory_uri() . '/custom-js.css', array(), ); } add_action( 'wp_enqueue_scripts', 'load_custom_js' ); // =============================================================================To know more how you properly load custom js, please check the codex: https://developer.wordpress.org/reference/functions/wp_enqueue_script/
Hope this helps.
March 11, 2016 at 1:18 pm #833900
smartsimulationParticipantthank you! will check it out.
March 11, 2016 at 5:54 pm #834208
JadeModeratorYou’re most welcome.
March 12, 2016 at 3:30 am #834645
smartsimulationParticipantactually, the above code causes an error. the whole site goes blank…
<?php // ============================================================================= // FUNCTIONS.PHP // ----------------------------------------------------------------------------- // Overwrite or add your own custom functions to X in this file. // ============================================================================= // ============================================================================= // TABLE OF CONTENTS // ----------------------------------------------------------------------------- // 01. Enqueue Parent Stylesheet // 02. Additional Functions // ============================================================================= // Enqueue Parent Stylesheet // ============================================================================= add_filter( 'x_enqueue_parent_stylesheet', '__return_true' ); // Add custom JS scripts // ============================================================================= function load_custom_js() { wp_enqueue_style( 'custom-js', 'get_template_directory_uri() . '/custom-js.css', array(), ); } add_action( 'wp_enqueue_scripts', 'load_custom_js' ); // =============================================================================March 12, 2016 at 3:39 am #834649
ChristopherModeratorHi there,
Please add JS file URL instead of
/custom-js.css.e.g:
custom-js-folder/custom-js-file.jsHope it helps.
March 12, 2016 at 3:40 am #834653
smartsimulationParticipantYes, I see that now (I was taking your example code too literally). Thanks.
March 12, 2016 at 3:44 am #834657
ChristopherModeratorYou’re welcome.
March 12, 2016 at 4:10 am #834671
smartsimulationParticipanthmmm. still having problems. maybe I’m not understanding the relative URL scoping from the child theme’s functions php.
I have a js script at child theme’s root level (where functions.php is) and then:
function load_custom_js() { wp_enqueue_style( 'custom-js', 'get_template_directory_uri() . '/scrollissimo.js', array(), ); } add_action( 'wp_enqueue_scripts', 'load_custom_js' ); // =============================================================================This causes an error.
March 12, 2016 at 4:23 am #834676
ThaiModeratorHi There,
Please try with this code instead:
function load_custom_js() { wp_enqueue_script( 'custom-js', get_template_directory_uri() . '/scrollissimo.js' ); } add_action( 'wp_enqueue_scripts', 'load_custom_js' );Hope it helps 🙂
March 12, 2016 at 4:29 am #834682
smartsimulationParticipantthat cleared the error! thanks! Am I right in thinking that if I use external js scripts like greensock tweening js which are on another server, I will need to copy them locally and use the same method as above? And do I use a load_custom_js() function for each and every one of them?
March 12, 2016 at 4:34 am #834685
ThaiModeratorHi There,
And do I use a load_custom_js() function for each and every one of them?
You don’t need to repeat adding the function load_custom_js(), please try with this code:
function load_custom_js() { wp_enqueue_script( 'TweenMax', '//cdnjs.cloudflare.com/ajax/libs/gsap/1.18.0/TweenMax.min.js' ); wp_enqueue_script( 'custom-js', get_template_directory_uri() . '/scrollissimo.js' ); } add_action( 'wp_enqueue_scripts', 'load_custom_js' );Hope it helps 🙂
March 12, 2016 at 4:36 am #834687
smartsimulationParticipantbeautiful, thanks.
March 12, 2016 at 4:46 am #834695
ThaiModeratorGlad we were able to help 🙂
If you need anything else, please let us know.
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-833289 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
