本文展示瞭如何在圖像中添加Pinterest的呼籲行動,僅在懸停在懸停上,以促進社交媒體參與度。 它強調了一種干淨,用戶友好的設計,並避免了不必要的依賴性。
>關鍵好處:
>為什麼可共享的圖像很重要:> 高質量,引人入勝的內容至關重要。 社交共享按鈕可以增強此功能,從而使用戶可以在Pinterest等平台上輕鬆共享單個元素(例如圖像)。 Pinterest尤其受益於視覺上吸引人的內容。
創建對Pinterest友好的圖像:pinterest引腳URL包括:
基本URL:
https://www.pinterest.com/pin/create/button/
:您的頁面URL(url編碼)。 url
:image URL(url編碼)。 media
:描述性文本(編碼為url,理想情況下是200個字符)。 description
> Pinterest的JavaScript提供了額外的功能,但此方法使用最小的代碼來簡單。 硬編碼(效率較低)方法:
>
此方法涉及為每個圖像手動添加HTML:
,
),將其定位並控制其在懸停在懸停上的可見性。 Pinterest徽標被嵌入為CSS中的base64編碼圖像。<a href="https://www.php.cn/link/af3b0930d888e15a07a36b9987b70858" target="_blank" class="pinterest-anchor pinterest-hidden"> <div class="pinterest-logo"></div> </a> <img src="" data-pin="pinIt" alt="">
>自動化(更有效)方法(使用jQuery):pinterest-anchor
>
pinterest-hidden
此jQuery代碼動態地生成了每個圖像的pinterest鏈接,並使用pinterest-logo
>
>自動化(更有效)方法(使用香草JavaScript):
這個香草javascript等效實現相同的結果,沒有jQuery:data-pin="pinIt"
$("img[data-pin='pinIt']").each(function() { $(this).before('<a href="https://www.php.cn/link/c84f1f1c3914a66236542d1166b01780' + encodeURIComponent($(location).attr("href")) + '&media=' + encodeURIComponent($(this).attr("src")) + '&description=' + encodeURIComponent($(this).attr("alt")) + '" target="_blank"><div class="pinterest-logo"></div></a>'); $(this).hover(function() { $(this).prev().css("display", "block"); }, function() { $(this).prev().css("display", "none"); }); });
進一步的考慮:
>這種方法乾淨且不引人注目,但在新窗口中打開份額可能會破壞用戶流程。 可以考慮彈出式替代方案。>
var pinables = document.querySelectorAll('img'); Array.prototype.forEach.call(pinables, function(el, i){ data = el.dataset; if (data.pin=='pinIt') { el.insertAdjacentHTML('beforebegin', '<a href="https://www.php.cn/link/c84f1f1c3914a66236542d1166b01780' + encodeURIComponent(window.location.href) + '&media=' + encodeURIComponent(el.src) + '&description=' + encodeURIComponent(el.alt) + '" target="_blank"><div class="pinterest-logo"></div></a>'); el.onmouseover = function(){ this.previousSibling.style.display='block'; } el.onmouseout = function(){ this.previousSibling.style.display='none'; } } });
(這些是為了簡短的,維持原始含義。)
以上是與Pinterest的呼籲行動共享圖像的詳細內容。更多資訊請關注PHP中文網其他相關文章!