(RESOLVED) Add Javascript library

Hi there,

I’m trying to add the Velocity.js Javascript library for use on my site. This is something new for me - and unfortunately I’m not having any success. The website: http://super.storiesandscience.co.za

This is what I’ve done:

I’ve added this code to functions.php in my child theme:

function add_velocity_script () {
  wp_register_script('velocity', get_stylesheet_directory_uri() . ‘/js/velocity.min.js’ , 
  array('jquery'),'1.0.0', false);
  wp_enqueue_script('velocity');
  }

add_action( 'wp_enqueue_script', 'add_velocity_script' );

I saved velocity.js in my child theme folder: /pro-child/js/velocity.js

Next, I added a line of on-page Javascript to test that the library is working, as follows:

$("#section-1").velocity("fadeIn", { duration: 3500 })

Unfortunately, the Javascript has no effect on ID #section-1.

I would appreciate any guidance you can give me!

Hi There,

The correct code should be:

jQuery ( function( $ ) {
	$("#section-1").velocity("fadeIn", { duration: 3500 });
});
function add_velocity_script () {
wp_register_script('velocity', get_stylesheet_directory_uri() . '/js/velocity.min.js' , array('jquery'),'1.0.0', false);
wp_enqueue_script('velocity');
}

add_action( 'wp_enqueue_scripts', 'add_velocity_script' );

Perfect. Thanks!

You’re welcome.