Web Design Forum: Help fading background images with jQuery - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Help fading background images with jQuery

#1 User is offline   JamesW 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 320
  • Joined: 28-July 09
  • Reputation: 2
  • Gender:Male
  • Location:London/Essex, UK
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 24 December 2009 - 12:58 AM

I'm trying to fade the background image of my header between several different coloured images using jQuery, I've spent ages trying to work it out myself and can't even manage to find a decent example I could apapt myself.

I've got it working with images inside a Div using a slideslow plugin but I need do it using background images..

I'm not asking for someone to write it for me just to point me in the right direction..

Here are a few random bits of code I'm basically hoping to combine somehow :rolleyes:


$(document).ready(function(){
						   
    $(".header").fadeTo(2000, 1).fadeTo(1000,0).fadeTo(2000, 1);
	
});					   



$(this).css({'background' : 'image1.png'});
$(this).css({'background' : 'image2.png'});
// etc.. //



As you've probably already worked out I'm new to jQuery and don't really have a clue what I'm doing :)

Thanks
0

#2 User is offline   Mark L Bentley 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 279
  • Joined: 04-June 08
  • Reputation: 13
  • Gender:Male
  • Location:Cambridge
  • Experience:Intermediate
  • Area of Expertise:Web Developer

Posted 01 January 2010 - 06:55 PM

James,

I would sugggest putting the background images in an array. Then use a for loop to go through the array. Something like.

bkgroundImages = new Array('image1.png', 'image2.png');

for (i=0; i<bkgroundImages.length; i++){

$('.header').css('background', i);

}  



Then you want to add some animation to make them fade in and out. If you wanted it to go back to the beginning you'd have to put an if statement in there too.
0

#3 User is offline   rallport 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 3,813
  • Joined: 03-January 10
  • Reputation: 266
  • Gender:Male
  • Location:England, UK
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 03 January 2010 - 11:39 AM

View PostJamesW, on 24 December 2009 - 12:58 AM, said:

I'm trying to fade the background image of my header between several different coloured images using jQuery, I've spent ages trying to work it out myself and can't even manage to find a decent example I could apapt myself.

I've got it working with images inside a Div using a slideslow plugin but I need do it using background images..

I'm not asking for someone to write it for me just to point me in the right direction..

Here are a few random bits of code I'm basically hoping to combine somehow :rolleyes:


$(document).ready(function(){
					 
 $(".header").fadeTo(2000, 1).fadeTo(1000,0).fadeTo(2000, 1);
	
});				 



$(this).css({'background' : 'image1.png'});
$(this).css({'background' : 'image2.png'});
// etc.. //



As you've probably already worked out I'm new to jQuery and don't really have a clue what I'm doing :)

Thanks


Can be done in a single line of code using JQuery's innerfade plugin or the minified version of the cycle plugin.

No need to reinvent the wheel 8)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users