我可以为Facebook分享按钮添加自定义的Facebook图标吗?
以下是我尝试过的代码,但我无法用自定义图标替换默认的徽标。
<div class="fb-share-button"
data-href="<?php echo SITE_URL;?>product/<?php echo $this->uri->segment(2);?>"
data-layout="link"></div>
我可以为Facebook分享按钮添加自定义的Facebook图标吗?
以下是我尝试过的代码,但我无法用自定义图标替换默认的徽标。
<div class="fb-share-button"
data-href="<?php echo SITE_URL;?>product/<?php echo $this->uri->segment(2);?>"
data-layout="link"></div>
使用 Facebook API 可供选择的样式数量有限。您可以更改“布局”,而不是“图标”。其中一个默认的布局是“icon_link”。
如果您想使用自己的样式/图像:我可以在不使用分享按钮的情况下使用共享对话框吗?
另一种简单但原始的方法是:
<a href="https://www.facebook.com/sharer/sharer.php?u=http://example.com">
<img src="./youimage.png" alt="share icon">
Link text
</a>
<ul class="sharing-buttons">
<li>
<a class="fb-xfbml-parse-ignore" target="popup" onclick="window.open('https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fdengdeney.blogspot.com.tr%2F&src=sdkpreparse','popup','width=600,height=500'); return false; " href="https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fdengdeney.blogspot.com.tr%2F&src=sdkpreparse">
<img src="
https://drive.google.com/uc?id=0B6hjXoGtqTbPRDN0cG9BVnozdEk" border="0" /></a>
</li>
</ul>
创建您自定义的HTML元素,并通过单击它来触发Facebook分享对话框。
<a href="#" class="facebook-bg"><i class="fa fa-facebook"></i></a>
$('a.facebook-bg').click(function(event){
event.preventDefault();
event.stopPropagation();
FB.ui({
method: 'share',
href: 'http://url_of_your_page'
}, function(response){});
});
别忘了先加载fb SDK。
https://developers.facebook.com/docs/sharing/reference/share-dialog
我曾经苦苦挣扎了数小时,试图创建一个只包含图片和弹出窗口的自定义分享功能,而这是唯一让我成功的方法。
从顶部帖子中列出的链接“Facebook-Social-Button-Plugin”中获取按钮配置器的代码
添加下面显示的调整后的元数据到配置器中
重写CSS
`.fb-share-button,.fb_iframe_widget,#facebook { width: 70px !important; height: 70px !important; margin: 0 auto; margin-top: -46px !important; background: url(../img/like.png) no-repeat !important; background-size: contain !important; }
.fb-share-button a { width: 70px; height: 70px; }
.fb_iframe_widget span { display: inline-block; position: relative; vertical-align: bottom; width: 70px !important; height: 70px !important; text-align: justify; }
.fb_iframe_widget iframe { position: absolute; width: 70px !important; height: 70px !important; }
.fb_iframe_widget iframe #facebook .inlineBlock { display: inline-block; zoom: 1; background: transparent !important; width: 70px !important; height: 70px !important; }
._2tga._3e2a { background: transparent !important; color: transparent !important; border-radius: 35px !important; width: 70px !important; height: 70px !important; }
path[Attributes Style] { fill: transparent !important; }`
删除锚点中的“分享”(我的布局只是一张图片)或更改它
可选:如果您想显示引用文本,只需在链接末尾添加它,如下所示(您也可以像这样更改链接的标题和描述)
-可选项2:如果您想将链接作为弹出窗口分享/打开,请在锚点上添加window.open onclick函数
带有弹出窗口和无文本引用的完整div示例:
<div class="fb-share-button" data-href="https://developers.facebook.com/docs/plugins/" data-layout="button" data-size="large" data-mobile-iframe="true"><a class="fb-xfbml-parse-ignore" target="popup" onclick="window.open('https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Fplugins%2F&src=sdkpreparse"e=here+comes+the+quote','popup','width=600,height=500'); return false;" href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Fplugins%2F&src=sdkpreparse"e=here+comes+the+quote"></a></div>
(数据大小和数据布局并不重要,因为CSS会被覆盖)
我相信有更好的方法来做到这一点,但我找不到任何!我尝试使用FB.ui,但它没有起作用。
我希望这能帮助到某些人!