Thursday, February 26, 2015

Share Images with a Pinterest Call-to-action

In this article, I’ll demonstrate how to add a Pinterest call-to-action on top of an image when a user is actively interacting with it.


Firstly, let’s look at why you would even want to do that.


Sharing Is Caring


Picture of a tea pot with a Pinterest share button appearing on hover

What constitutes good content often depends a lot on the particular needs and interests of end users. Good content might be attractive, effective, simple, functional, informative, inspiring … and so on.


We are used to adding social network buttons or links to share a page (ideally via fat-free buttons). Facebook, Twitter and Google+ are often the primary must-haves.


We may also want users to be able to share parts of our page. Page content is often made of chunks, and each of these chunks can be provided with its own preferred social network sharing feature.


For instance, a quote can be targeted to fit Twitter’s 140-character limit, and a picture can be aimed for Pinterest.


Let’s look at how you set up your images to be shared on Pinterest.


Anatomy of a Pin URL


A Pinterest Pin URL is made of four components:



  • the Pinterest part of the URL: http://ift.tt/1kj44ES

  • the url parameter: the address of the page to link to, URL-encoded

  • the media parameter: the address of the picture to share, URL-encoded

  • the description parameter: the descriptive text shown on Pinterest, URL-encoded, 500 characters max, but 200 characters seems to be the best choice.


Some HTML data elements can be added if you add Pinterest’s own JavaScript, especially data-pin-do and data-pin-config, but it won’t be needed in this case, as this is a fat-free approach where we rely on the strict minimum amount of code.


The Hard-coded Way


The code we want to get looks like this:


[html]

<description>[/html]

Each sharaeble picture (marked with the data-pin attribute pinIt) is prefixed with an anchor to the Pinterest sharing page with the right attributes in its URL, embedding a div to display the logo.


Three CSS classes are used here: pinterest-anchor, which absolutely sets the Pinterest logo position on the top-left corner of the picture; pinterest-hidden, which sets the visibility status of the logo, and pinterest-logo, the logo itself, 40x40 pixels, encoded in base64 in the CSS.


[html].pinterest-anchor { margin-left:10px; margin-top:10px; position:absolute; z-index:42; width:40px; height:40px; } .pinterest-hidden { display:none; } .pinterest-anchor:hover { display:block !important; } .pinterest-logo { background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAACXBIWXMAAAsTAAALEwEAmpwYAAAABGdBTUEAALGOfPtRkwAAACBjSFJN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j5CJhYFNUwfYKkYMfn06fpTh98sXDMKBIXj1frtxneHFnJkMH/buBmc4hr/gBIfhQMZ/DPAMAxBA4F7dP2AUw+IcLwDVHMCMImBqhlq8XLnC8GxCL8O3O3cZRENCGdhBocsIGVn4A+wJfjl3Btiq3s7w5fw5hl+vXjIwARsUkJoDS4BAy+V/DJB+MUAAscC7ff8Z8UYxJHqA2oBNdVF9A6RG7A+GHzdvgJtoL5ctYXi1cgUDEzcXAwuwMwQaa/n75Quk6Pj7F5KigbUJOE/g6hT//w8pK6HFDEAAscAKakZYSY7PgUD3saqqAXMsojb4AyyCvp45A2xmcUAKFlAXAti5/wUMOcigDSMiDTMQtgPiQEgGAUUzQACBQvDXr99/WJhY2CCNif/4xmcYGXh19FCrqlu3GH48esLADGoVoxRTjATMwjHqwwjpw/wAt54YfgEEEAsLM8u9z5++6PwDllegsuwvqIGAYxgDJMolJ4ea/vbuRVRVlAKgi5iBhf8/YGB9+fSFAeQ2gABi4uPhq/3w4T3DK2Au5JCQhPQlQHYBm1Xgpj8yBqZBNmDHG55ngGns/Y6dwJqKGVMtSRiSK0B2g9wAcsuHD+8Y+Hh4awECiIWVhXU/Pw/fzvs3brgzAQtlMSkZBkZgi+Tvr5+Y6QXYO+OUlERE72lg2gP6lkVMksLxX0YGZmDm+c/BzvDy+TMGoFsY+Hn4d7KysO0HCCAWxv+MHwX5BaKBlfqCO9eu+Lx+8ZyBl4ePgR1YzmGMWAH5AsAo/S4tCc6Z96fOYPgCzCSMaK0akmMWmBF+Aptun798YvgIbMYJ8PJtEeAXSAC5DSCAGHerQerUnz9/cv/5/dvly9evLT/+/FZiBA1sYgHS0tIM3MD+yhdg9L548oSBWiPZ/xkZf3GwsN7j4eauZWFl3c3Ozv4V5HCAAAMAlTuh/0H0Uz0AAAAASUVORK5CYII=") no-repeat center center; background-size: 40px 40px; height: 100%; width: 100%; }[/html]

The animating part – showing and hiding the logo on hovering the picture – is handled in JavaScript, using jQuery notation:


[html]$("img[data-pin='pinIt']").each(function() { $(this).hover(function() { $(this).prev().css("display", "block") }, function() { $(this).prev().css("display", "none") }); });[/html]

Continue reading %Share Images with a Pinterest Call-to-action%




by Alexis Ulrich via SitePoint

No comments:

Post a Comment