Jquery

JQuery Tutorials

JQuery Resources

                                                   JQuery




ExploreJQuery.Com

 





JQuery Lightbox
 





 JQuery Accordion





JQuery Autocomplete
 

 Affiliate Marketing Recommended Products

The Affiliate Code   Profit Miracle   Maverick Money Makers
               

The Affiliate Code is an amazing training product by Michael Jones. He will teach you how he made $65,000 in one month. Michael Jones is also the creator of the extremely popular ClickBank Code.

 

Profit Miracle is a great product that will provide you with a shortcut on creating and marketing your content. This product will save you time and money with your affiliate marketing ventures

 

Maverick Money Makers was developed by millionaires and has proven to generate at least $354.97 per day from home when you are just starting out. This course is good for beginners and intermediate affiliates

Read more>>>   Read more>>>   Read more>>>
   
   
   
  Bookmark and Share
  
JQuery Sprite Animations
      
Mar
12
Jamal Ahmad

jam05pgs

0 Comments  |   3837 Hits
Tags:   jquery,jquery animations,jquery sprite animations
 

Spritely is a simple plugin with only two key methods, sprite() and pan() both of which simply animate the background-image css property of an element. The difference between the two is that a 'sprite' image contains two or more 'frames' of animation, whereas a 'pan' image contains a continuous image which pans left or right and then repeats.

jQuery Sprite Animations

Typically, in either case, you would use a png file (with or without transparency) for this. You might wish to use a transparent gif for Internet Explorer 6, though it probably won't look as good. Your html elements must already be the correct size you want the sprite to appear, but the background image will typically be larger than the html element, and the spritely methods reposition the background image within the html element.

Quick Start

If you're impatient to try out Spritely and want to see some self-contained working examples, you can download some sample code as a zip file.

Animation an image with the Sprite() Method

Here's a quick example to get you started... The following method animates one of the bird 'sprites' flying around this page. The 'sprite' is composed of three frames in a transparent png image, where each frame is side by side:

jQuery Sprite Animation

Now we simply need to create a div called 'bird', style it to exactly the correct size (180x180 pixels in this case), and animate it with the sprite() method. The two options we need to use are 'fps' (frames per second) and 'no_of_frames', e.g. three frames for the above image:

$('#bird').sprite({fps: 12, no_of_frames: 3});

To make the mouse attract the sprite when you click the screen, use this:

$('#bird').sprite({fps: 12, no_of_frames: 3}).activeOnClick().active();
$('body').flyToTap();

The active() method makes this sprite the active sprite on launch - otherwise a sprite with activeOnClick() becomes active only when you click it (or touch it using an iPhone/iPad).

The $('body').flyToTap() method watches for a click on the page at which point, after any current move is complete, the sprite moves to the clicked location. After a few second, if a random movement method has been applied (see below), it then moves away again.

To make the sprite move in a random way, within pixel constraints (speeds are in milliseconds), use this:

$('#bird')
      .sprite({fps: 8, no_of_frames: 3}
      .spRandom({
          top: 70,
          left: 100,
          right: 200,
          bottom: 340,
          speed: 4000,
          pause: 3000
      });

Panning a background image with the PAN() method:

Here's how you can 'pan' a background image, like the hills in the demo at the top of this page.

jQuery Sprite Animations

To make the background image pan continually to the left, create an html div element smaller than the image itself and use css to place your image as the background image, making sure you set the background image repeat to 'repeat-x', e.g. it repeats continuously in the horizontal axis.

Now animate it with spritely's 'pan()' method:
$('#trees').pan({fps: 30, speed: 2, dir: 'left'});

You can adjust the speed (pixels per frame) and frames per second independently of one another. Why? Because a lower speed will result in a smoother pan, however a higher frames per second may result in slower performance (especially on devices like iPhone). You'll need to experiment to get the right balance between smooth animation and page performance.

To layer background images over each other, simply place the html images below each other, or adjust the 'z-index' css property, then set the fps and speed properties to give the illusion of depth. A more distant background image should move more slowly (lower fps) than a close-up one.

One Final Point:

Use Spritely sparingly. A little Spritely goes a long way, but over-ambitious use of these techniques may lead to poor performance, especially on mobile devices. A little movement on a large page may be better than a lot of movement on a small one.

For more examples, read the source code of this page!

 

Live Demo jquery Sprite Animations

Download jquery Sprite Animations

[ Stumble Upon ] [ Facebook ] [ del.icio.us ] [ furl ] [Sphinn] [ Digg ] [ Twitter ] [ Technorati ] [ Reddit ] [ Subscribe To RSS Feeds ]

0

 
 
 
   
 
Leave your comments
 
  Your comments  

     
name  

     
  email  

     
website    

     
5 + 3 =    

     
   
     

 

 

Follow me on twitter

Follow me on facebook

 

 
   

   

affiliate_link

   

affiliate_link

   

Buy Now - PayPal

   
 
   
  JQuery Community
 
 
tissa
darrenrowse
amour
niculae
sassyqarla
summerzeet
electrostar
good-pens
kh
travelhotelworld
tunyalitk
masterartrep
dain22
bloggersun
jameslove4enao
thebeespace
majalahpatani
caryngf
wonkapromotions
jam05pgs
 
  View more bloggers   Join Community
   
   
  JQuery Popular Posts
 
 
JQuery Beautiful Image Slide Show in New Way
Good Pens, Saturday 18th April 2009

Ajax Animated Live Search
Tunya Litk, Monday 4th May 2009

Ajax instant edit
Jamal Ahmad, Friday 15th May 2009

JQuery Autocomplete with Ajax PHP and MySQL
Jamal Ahmad, Sunday 14th June 2009

Ajax fancy Captcha with JQuery and PHP
Majalah Patani, Friday 8th May 2009
   
   
  JQuery Poll
 
 

Would you like to have a website which will provide you all facilities listen music, friendship, photo sharing and blog?

 

Yes

No
I dont know
 

 
   
  JQuery Categories
 
 
JQuery
JQuery AJAX
JQuery Banners
JQuery Browsing
JQuery CSS
JQuery Forms
   
   
   

 

 

 

 

© Copyright Explore JQuery, all rights reserved
A company registered in north America, Europe, Asia and Middle East as Explore Group.