Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-09-2013, 02:36 PM   PM User | #1
a4udi
Regular Coder

 
Join Date: Jan 2005
Posts: 181
Thanks: 5
Thanked 0 Times in 0 Posts
a4udi is an unknown quantity at this point
Jquery Fade Effect

Hi,

I'm trying to do a simple image cycle but I want to add either a fade or slide effect it. I've got a <div id#home-image-container"> which is basically the middle section of my page with a background image and it cycles through 3 different backgrounds.

Here is the code I'm using:

Javascript
Code:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.3.min.js"></script>
<script type="text/javascript">
jQuery( function( $ ) {
    var images = [ "images/background-02.jpg", "images/background-03.jpg" ];
    var currentImage = 0;

    function changeBackground() {
        $( '#home-image-container' ).css( { backgroundImage: 'url(' + images[ ++currentImage ] + ')' } );
        if ( currentImage >= images.length - 1 ) {
            currentImage -= images.length;
        }
    }

    setInterval( changeBackground, 5000 );  
});
</script>
And the DIV
Code:
<div id="home-image-container" style="width:100%; height:690px; background-image:url(images/background-01.jpg); background-position:center; background-repeat:no-repeat; overflow:hidden;">
It works fine right now, but it just changes the background after a few seconds.. I want to add a fade or slide transition to the 3 backgrounds.
a4udi is offline   Reply With Quote
Old 02-09-2013, 05:06 PM   PM User | #2
SB65
Senior Coder

 
Join Date: Feb 2009
Location: West Yorkshire
Posts: 2,816
Thanks: 9
Thanked 681 Times in 675 Posts
SB65 will become famous soon enoughSB65 will become famous soon enough
You can't fade the background-image, unless you fade the whole div with it. Better to use images and then fade them. Have a look at this for an approach to crossfading the images.
__________________
Use the W3C HTML Validator and CSS Validator to check your code and Firebug to see what css is applied to an element
Read Steve Krug's book Don't Make Me Think - essential reading on web usability
I don't recommend much, but I do recommend Clook for UK web hosting
SB65 is offline   Reply With Quote
Old 02-10-2013, 06:11 PM   PM User | #3
a4udi
Regular Coder

 
Join Date: Jan 2005
Posts: 181
Thanks: 5
Thanked 0 Times in 0 Posts
a4udi is an unknown quantity at this point
Perfect, I went the image route and have it working! Thanks.
a4udi is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:34 PM.


Advertisement
Log in to turn off these ads.