I finally have this working now but would like to know how I can use JQuery's animate function to make the background image changes fade in nicely when you hover over the list items on the homepage:-
http://www.thebalancedbody.ca/
The Code to make this happen so far is:-
$("ul#frontpage li#277 a").hover(
function() {
$('#homepage_container').css('background-image', 'url(http://www.thebalancedbody.ca/wp-content/themes/balancedbody_V1/images/nutrition_background.jpg)');
},
function() {
$('#homepage_container').css('background-image', 'url(http://www.thebalancedbody.ca/wp-content/themes/balancedbody_V1/images/default_background.jpg)');
}
);
$("ul#frontpage li#297 a").hover(
function() {
$('#homepage_container').css('background-image', 'url(http://www.thebalancedbody.ca/wp-content/themes/balancedbody_V1/images/vibration_training.jpg)');
},
function() {
$('#homepage_container').css('background-image', 'url(http://www.thebalancedbody.ca/wp-content/themes/balancedbody_V1/images/default_background.jpg)');
}
);
etc etc
How would I add the ANIMATE function to this please - thanks!!!
Thanks
Jonathan
I had the same problem, after loads of research and Googling, I found the following solution worked best for me! plenty of trial and error went into this one.
--- SOLVED / SOLUTION ---
JS
CSS
It can be done by jquery and css. i did it in a way that can be used in dynamic situations , you just have to change background-image in jquery and it will do every thing , also you can change the time in css.
The fiddle : https://jsfiddle.net/Naderial/zohfvqz7/
Html:
CSS :
JS:
Ok, I figured it out, this is pretty simple with a little html trick:
http://jsfiddle.net/kRjrn/8/
HTML
javascript
CSS
The simplest solution would be to wrap the element with a div. That wrapping div would have the hidden background image that would appear as the inner element fades.
Here's some example javascript:
and here's the html to go along with it:
I don't think this can be done using jQuery's
animate
function because the background image does not have the necessary CSS properties to do such fading. jQuery can only utilize what the browser makes possible. (jQuery experts, correct me if I'm wrong of course.)I guess you would have to work around this by not using genuine
background-image
s, butdiv
elements containing the image, positioned usingposition: absolute
(orfixed
) andz-index
for stacking. You would then animate thosediv
s.