This option will reset the home page of this site. Restoring any closed widgets or categories.

Reset

Background Animations Using MooTools

href="http://davidwalsh.name/dw-content/background-animation.php"> src="http://davidwalsh.name/dw-content/bg-clouds.jpg" alt="MooTools background animation" />

One of the sweet effects made easy by javascript frameworks like MooTools and jQuery is animation. I ran across href="http://codingkitty.com/demo/animated-background/" rel="nofollow">this great jQuery tutorial that walks you through animating a background image of a page. Here’s a quick MooTools code snippet that shows you how you can add this sweet effect to any element on a page.

class="actions"> href="http://davidwalsh.name/dw-content/background-animation.php" class="demo">View Demo class="clear">

The CSS

#animate-area	{ background:url(bg-clouds.png) 0 0 repeat-x; }

The first step is assigning the image as a background image for our given container. Be sure to repeat the background horizontally!

The MooTools Javascript

window.addEvent('domready',function() {
	//settings
	var duration = 5000;
	var length = 2000;
	var count = 0;
	var tweener = $('animate-area').set('tween',{ duration: duration, transition: 'linear' });
	//showtime!
	var run = function() {
		tweener.tween('background-position','-' + (++count * length) + 'px 0px');
	};
	run();
	run.periodical(duration);
});

The first step, as always is getting our settings ready for the show. The next piece is putting the animation function in place. We increment the negative background left position counter calculation to keep the show rolling. Last step is playing the show!

class="actions"> href="http://davidwalsh.name/dw-content/background-animation.php" class="demo">View Demo class="clear">

Make sure the animation speed is very slow and subtle — a rapid background speed could make your users pass out. On the other hand, implementing it tastefully will make your website unique.

id="aspdf"> href="http://davidwalsh.name/wp-content/plugins/as-pdf/generate.php?post=4830" rel="nofollow"> Download PDF

Don’t forget to href="http://twitter.com/davidwalshblog">follow me on Twitter and be sure to visit href="http://scriptandstyle.com">Script & Style for the best Javascript and CSS articles around! href="http://buysellads.com/buy/detail/1687">Sponsor the David Walsh Blog and get your brand in front of several thousand users per day!

href="http://davidwalsh.name/mootools-animate-background">Background Animations Using MooTools

Related posts:

  1. href='http://davidwalsh.name/css-fixed-position-background-image' rel='bookmark' title='Permanent Link: CSS Fixed Position Background Image'>CSS Fixed Position Background Image
  2. href='http://davidwalsh.name/jquery-random-color-animate' rel='bookmark' title='Permanent Link: jQuery Random Link Color Animations'>jQuery Random Link Color Animations
  3. href='http://davidwalsh.name/dwprogressbar-2-stepping-events-mootools-progress-bar' rel='bookmark' title='Permanent Link: dwProgressBar v2: Stepping and Events'>dwProgressBar v2: Stepping and Events
  4. href='http://davidwalsh.name/progress-bar-animated-mootools' rel='bookmark' title='Permanent Link: Animated Progress Bars Using MooTools: dwProgressBar'>Animated Progress Bars Using MooTools: dwProgressBar
  5. href='http://davidwalsh.name/external-favicon' rel='bookmark' title='Permanent Link: External Site Link Favorite Icons Using MooTools and CSS'>External Site Link Favorite Icons Using MooTools and CSS

View full post on David Walsh :: PHP, CSS, MooTools, jQuery, and Everything Else

No related posts.

Tagged with:         

10 Comments

  1. senshikaze

    awesome look, though i can see some people going overboard with this.

  2. Steven Schrab

    What? No Parallax effect? :P

  3. Tyler Abell

    This seems cool but may difficult to successfully implement into an effective design. It seems quite limited as well but don’t get me wrong, it’s a great way to animate a background with the simplicity of moo tools. I would suggest looking at snapjay.com and the code be hide it at code.snapjay.com…

  4. cake

    Hi,
    nice work. Could you convert sich special nice effect from jQuery to Mootools. This is an awesome effect.
    http://webdev.stephband.info/parallax.html

  5. Alex

    @cake
    There is a plugin for mootools called mparallax, but its developer’s website (Piksite.com) is down for some reason….

  6. Paul Winslow

    I’ve been meaning to look into fading background images from one-to-another with jquery/mootools.. don’t suppose you’d be willing to show how that’d work? Cheers, David.

  7. Tyler Abell

    @Paul Winslow:

    Paul you should check the site I provided above: code.snapjay.com

    You may find that jquery useful, but on snapjay.com he uses a background fader. I will be writing a article on this later tonight. I will let you know…

  8. Jeroen

    Hi David! Cool to see this work in Mootools! I’m using a Jquery version of this on my company site (Mediashake.nl). Works pretty good, but I wish I could save it’s state so the clouds won’t restart for each new page or refresh… any idea’s?

  9. Adriaan Nel

    I agree with Paul Winslow…fading background images into each other would make an awesome experiment!

  10. Kepler W.

    Hello David!

    Great thanks for your acceptance for the work ! Your are Cool!

    Regards!

    Kepler