I see this problem on a lot of WordPress blogs using a round Gravatar with Jetpack Hovercards. When you hover over a user’s Gravatar (often in the comments) there is a hover state that appears while the Hovercard loads and this hover state has the Gravatar image but it has the wrong aspect ratio. Below I explain how I troubleshoot and correct this issue.
Populate the Hoverstate
Update: Originally, this post only included the Manual Way to Populate the Hoverstate. I’ve since spent a little more time with this and added this function that encapsulates all the work that needs to be done.
If you copy and paste the following code into the Google Chrome Developer Tools Console, it should populate the hoverstate for the first Gravatar on the page.
(function() { | |
var gravCloneHtml; | |
jQuery('.grav-hashed').first().trigger('mouseenter'); | |
gravCloneHtml = jQuery('.grav-clone-a')[0].outerHTML; | |
setTimeout( function() { | |
jQuery('.grofile').trigger('mouseleave'); | |
}, 3000 ); | |
setTimeout( function() { | |
jQuery('body').append( gravCloneHtml ); | |
}, 4000 ); | |
}) (); |
Add Corrective CSS
You should now have the intermediate hover state Gravatar image displayed on your screen, even though you are currently in the Google Developer Tools pane. Now you can muck about with the CSS to correct the issue.
In my experience with circular gravatars, the following is a common fix.
.grav-clone-a { border-width: 1px !important; }
Update with Similar Problem: Box Sizing
I’ve found a similar problem, where non-circular Gravatar’s have a hover state with the wrong aspect ratio. Here you can see the wrong aspect ratio on the left with the correct aspect ratio on the right.
This problem can be corrected with the CSS line
.grav-clone-a img { box-sizing: content-box !important; }
Manual Way to Populate the Hoverstate
This method is now superseded by the function found above, however, I’m going to keep this code here for future reference.
Capture the Hover State Markup
Paste the following code into the Google Developer Tools console but do NOT press return (we don’t want to run this yet).
gravCloneHtml = jQuery('.grav-clone-a')[0].outerHTML;
Hover over the avatar to trigger the hover state and Gravatar Hovercard. Then press return.
You should see something like the following in the console.
Add the Hover State Markup for Editing
Move your mouse away from the Hovercard so it closes. Now paste the following code into the Google Developer Tools console and press return (yes, actually press it this time).
jQuery('body').append( gravCloneHtml );
Hi, Sal. I’m glad I stumbled across this post. I’m looking for a way to have Hovercards work for Authors but not Commenters. Do you have any suggestions for this?
Also – I look forward to meeting you at WCLHV next weekend. I’m speaking there also.
Cheers!
Hi Terri,
That is an interesting question. I’m not sure whether Jetpack’s Gravatar Hovercards supports this or not.
At the time of this writing, there are a number of filters applied when the module first starts up.
I’m not sure whether you could leverage any of these or not.
I’ll be at the Happiness Bar at WordCamp Lehigh Valley from 11:00am to noon. If you want to stop by during that window, I can take a closer look at it with you.
Your presentation topic of backups is a good one. I’ll look forward to your talk.