Hit Counter

About Me

Just want to make other happy and make them feel better when they see this blogg nothing else. This site is dedicated to my friends. I`m so thank full to all my school friends and to my college friends.

Wednesday, January 26, 2011

Automatically pull in user Gravatar images

I was browsing forrst.com and saw a pretty interesting code snippet
from Chris Coyier from CSS-Tricks which is pretty useful for WordPress
users and allows the gravatar of a commenter to be dynamically pulled
into the comment box as soon as the user has clicked out of the email
input field.

The Code

This code snippet is pretty easy to grasp. We're simple replacing the
background image of the div #avatar each time the user clicks out of
the email input field. you'll notice that we're also calling the
function MD5(). This is because Gravatar uses your email address
encoded into an MD5 hash as an id to pull your avatar. You also need
to include the function MD5() which is available in the Download.

$(document).ready(function(){

var email = $("#email"),
avatar = $("#avatar");

email.blur(function() {
avatar.css("background-image","url(http://www.gravatar.com/avatar/" +
MD5(email.val()) + ")");

});

});

The HTML

<div id="avatar"><img src="thumb.png" width="80" height="80"/></div>

<form class="gravatar">
<input type="text" onFocus="if(this.value=='Email Address')
this.value='';" onBlur="if(this.value=='') this.value='Email
Address';" value="Email Address" name="s" id="email" />
</form>

My Headlines

SonicRun.com Submit Your Site To The Web's Top 50   Search Engines for Free!