I'm trying to load jQuery but I can't seem to get it to work properly.
On this page here: https://koehlerrice.com/about-3/ I'm trying to get the image to fade from one color to another on the page load. Right now to keep it simple I'm trying to go from #000 to #fff
This is where I'm at after some
Here is my css:
.fading-start1
{
background-color: #000000!important;
transition: background-color 3s linear!important;
-moz-transition: background-color 3s linear!important;
-o-transition: background-color 3s linear!important;
-webkit-transition: background-color 3s linear!important;
}
.fading-finish1
{
background-color: #fff!important;
}
Here is my function I believe is loading jQuery
function avtheme_scripts() {
wp_enqueue_script( 'av-about-fade', get_stylesheet_directory_uri() . '/about-fade.js', array( 'jquery' ), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'avtheme_scripts' );
And, here is my JS file
(function( $ ) {
'use strict';
$( document ).ready( function() {
if( $( '.fading-start1' ).length > 0 ) {
setTimeout( function() {
$( '.fading-start1' ).addClass( 'fading-finish1' );
}, 3000 ); }
} );
} )( jQuery );
After a hand full of edits and help from Tony below here is where I'm at. I was able to see it working several times but it seems to be inconsistent. Like I would refresh the page, go to a new browser or incognito and it would behave differently. More often than not it's just fading for 3 seconds into #000, then another 3 seconds into #fff.
I tried different versions of your code provided below. Couple questions:
1: Does this work with RBBA? My real goal was to fade from something with an opacity of like .8 to .95.
2: Those new jQ functions you provided with the 3-second delay, are those going in the .js file or in the functions.php? I think I'm confused about what's going where. Right now I have them in the .js file.
3: Although I know 0 jQ, I tried to combine the two functions you gave me into one. Does that work like that? The one with the 3-second timer and the one that checks the length. Does that work or do they need to be separate? If so, are they both going in the .js file, functions.php or?
Thank you