I'm in the process of converting an HTML homepage to WordPress format and I'm not sure what to do with the Javascript that's included within the of the index.html homepage (as opposed to the JS located in separate files). To see what I'm talking about, view the source of http://tstand.com - the script starts at line 89 and ends at line 239.
My instinct was to move this script to a separate Javascript file (I named it menuscroll.js) and then enqueue it via functions.php as I did with all other style sheets and Javascript files associated with that page, as seen below.
function wpse_enqueue_page_template_styles() {
if ( is_page_template( 'page-2820.php' ) ) {
wp_enqueue_style( 'main', get_template_directory_uri() . '/assets/css/main.css' );
wp_enqueue_style( 'animate', get_template_directory_uri() . '/assets/css/animate.css' );
wp_enqueue_style( 'animate-min', get_template_directory_uri() . '/assets/animate.min.css' );
wp_enqueue_style( 'component', get_template_directory_uri() . '/assets/css/component.css' );
}
}
add_action( 'wp_enqueue_scripts', 'wpse_enqueue_page_template_styles' );
add_action('wp_enqueue_scripts','Load_Template_Scripts_wpa83855');
function Load_Template_Scripts_wpa83855(){
if ( is_page_template('page-2820.php') ) {
wp_enqueue_script( 'default', '//use.edgefonts.net/source-sans-pro:i6,n6,n4,i4,i3,n3,n7,i7:default.js');
wp_register_script( 'menuscroll', get_template_directory_uri() . '/assets/js/menuscroll.js');
wp_enqueue_script( 'menuscroll.js', get_template_directory_uri() . '/assets/js/menuscroll.js');
}
}
The custom template I've created is page-2820.php. A resource online led me to believe that I should register it before enqueueing it, however still no success. All other CSS/JS files seem to be working properly.
Here are the contents of menuscroll.js
// JS for showing features titles
$(function(){
$("#i1").hover(function(){
$('#desc-i1').fadeIn();
}, function() {
$('#desc-i1').fadeOut(100);
});
$("#i2").hover(function(){
$('#desc-i2').fadeIn();
}, function() {
$('#desc-i2').fadeOut(100);
});
$("#i3").hover(function(){
$('#desc-i3').fadeIn();
}, function() {
$('#desc-i3').fadeOut(100);
});
$("#i4").hover(function(){
$('#desc-i4').fadeIn();
}, function() {
$('#desc-i4').fadeOut(100);
});
$("#i5").hover(function(){
$('#desc-i5').fadeIn();
}, function() {
$('#desc-i5').fadeOut(100);
});
$("#i6").hover(function(){
$('#desc-i6').fadeIn();
}, function() {
$('#desc-i6').fadeOut(100);
});
$("#i7").hover(function(){
$('#desc-i7').fadeIn();
}, function() {
$('#desc-i7').fadeOut(100);
});
});
var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ? true : false;
jQuery(document).ready(function($){
if(!isMobile) {
$(window).scroll(function(){
if ($(this).scrollTop() < $('#s4').offset().top-50) {
$('#features-area').removeClass('fadeIn')
$('#features-area').addClass('fadeOut')
}
if ($(this).scrollTop() >= $('#s4').offset().top-50) {
$('#features-area').addClass('fadeIn')
$('#features-area').removeClass('fadeOut')
}
<!--#s3 text fade in fade/ out -->
if ($(this).scrollTop() < $('#s3').offset().top-350) {
$('#s3-left').removeClass('fadeInLeft')
$('#s3-left').addClass('fadeOutLeft')
}
if ($(this).scrollTop() >= $('#s3').offset().top-350) {
$('#s3-left').addClass('fadeInLeft')
$('#s3-left').removeClass('fadeOutLeft')
}
});
}
});
I would strongly appreciate it if someone could point out what I'm doing wrong here.
Thanks a lot! :)
EDIT: Removed Jquery and Jquery-ui from enqueue script, added contents of menuscroll.js
is_page_template('page-2820.php')won't fire.