Really Useful Javascript Animation


by Dale Stubbart

Expressive Animated Websites

Cards:Rotate

To place rotatable cards on your website, use these scripts in the <head> section of your html page.
xa_animate_init() &n-; Init the overall animation
xa_card_init() &n-; Init the cards
xa_card_size_init() &n-; Init the card size
xa_card_rotate_init() &n-; Init the card rotation variables. You can override them afterwards.
xa_card_rotate_event='click'; Value is click or hover.
xa_card_rotate_speed='normal'; Value is slowest, slower, slow, normal, fast.
xa_card_rotate_type=['standard',xy]; xy is based on xa_card_type. Value of first element is standard, magic, dancer, switch, or any number of degrees for the front of the card.
xa_card_rotate_degrees_init() &n-; Init the front and back rotation degrees.
xa_card_rotate_degrees=[front,back];
front degrees are set on the rotater div. back degrees are set on the back div. Both are based on xa_card_rotate_type.
standard sets the rotation degrees for the front of the card to 180. magic sets it to 260. dancer sets it to 900. The back of the card is set to 360-remainder(front degrees/360). Switch rotates around the left edge of the card. Rotate is set to -180,180. Switch uses both rotate and translate (move) transformation. The others only use rotate.
xy is the rotation direction. This should be x for business cards and y for playing.

xa_card_rotate_build(card_front_img,card_front_info,card_back_info,xa_el)
xa_card_rotate_build will build a card which will rotate when the user clicks or hovers. This function will build the card where you specify, with the info you want.

card_front_img is the url of the image for the front of the card. For business cards, the img covers 1/2 of the card. For playing cards, the img covers the entire card, except the space for the lines specified for the title by xa_card_title_lines.
card_front_info is an array of the info/title placement and the info or title. The placement is top, bottom, left, or right. For business cards, placement is typically left or right. For playing cards, placement is typically top or bottom and is for a title. For playing cards, the title is assumed to be 2 lines which goes above or below the card. For business cards the info (or title) goes within the card. The info is vertically centered by counting the number of <br>'s within the info. I could have gotten more fancy with this, but decided to keep it simple.
card_back_info is the info on the back of the card. The info on the back of the card typically contains <p> and other simple html tags. You can include styles, and whatever.
xa_el is the element (normally a div) which will contain the card. card01 in this example.

The entire card deck should look something like:
<div><div id="card01" style="float:left;margin:.5em;"></div><script>xa_card_rotate_build(card_front_img,card_front_info,card_back_info,"card01")</script><div id="card02" style="float:left;margin:.5em;"></div><script>xa_card_rotate_build(card_front_img,card_front_info,card_back_info,"card02")</script>...</div>

Example: Select a rotate type and click Submit. Then click on the card to rotate.