使用 Google+1 按钮的自定义图像?
我想在页面上包含一个“google+1”按钮,但我想使用具有自定义尺寸的自定义图像,并且最好不使用 JavaScript,就像 Facebook 和 Twitter 一样。我不在乎它现在是否不显示计数。
I want to include a "google+1" button on a page, yet I want to use a custom image with a custom size for it and preferably without javascript, much like is possible to do with Facebook and Twitter. I don't care if it don't show the count number for now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
最后!找到了解决这个问题的好方法。如此简单且有效:) 希望它对您有帮助!
来源:http://notesofgenius.com/how-develop-custom-google-加号按钮/
Finally! Found a nice solution to this problem. So simple and working :) Hope it helps you!
Source: http://notesofgenius.com/how-develop-custom-google-plus-button/
这是来自 Google 开发者页面的官方示例:
另请注意网址已更新。
This is the official example from the google developers page:
Also consider that the URL was updated.
使用不透明度 0 使其不可见。然后使用背景使其看起来像你想要的。
use opacity 0 to just make it invisible. Then use background for making it looks like what you want.
您可以覆盖图像并保留功能:
http://tcg.ellininc.com/buttonTest/
我的对于任何无关的 CSS 表示歉意。
You can overlay an image and keep functionality:
http://tcg.ellininc.com/buttonTest/
My apologies for any extraneous css.
如果您愿意使用 JavaScript,这将提供更官方的体验。
HTML
JavaScript
如果您在全局范围内包含该函数,则可以在各处使用此类按钮,而无需使用多个冗长的内嵌
onClick
。If you were willing to use JavaScript, this will give a more official experience.
HTML
JavaScript
If you include that function globally, you can have such buttons all over the place without using multiple, lengthy, in-line
onClick
s.我使用 Chrome 的元素检查器来找出要定位的元素(您也可以使用 Firebug):
+1 的原始精灵在这里: https://ssl.gstatic.com/s2/oz/images/stars/po/Publisher/sprite.png
在我的实现中,渲染的
具有
a-sb-ig-e
和a-sb-ig-ps-e
类及其父类是一个带有a-sb-ML
类的从那里,您可以简单地在自己的 CSS 中设置按钮的样式。同样,您还可以通过检查计数器气泡并找出其元素的类来设置计数器气泡的样式。
编辑:由于 +1 按钮是在 iframe 内调用的,因此我上面描述的内容将不起作用。您可以做的就是定位 +1 div 并将其不透明度设置为 0,然后将其放置在您自己的图像之上。要定位的 div ID 为
#___plusone_0
I used Chrome's element inspector to figure out the elements to target (you could also use Firebug):
The original sprite for +1 is here: https://ssl.gstatic.com/s2/oz/images/stars/po/Publisher/sprite.png
On my implementation, the rendered
<a>
has a classes ofa-sb-ig-e
anda-sb-ig-ps-e
and its parent is a<div>
with a class ofa-sb-ML
From there, you could simply style the button within your own CSS. Similarly, you can also style the counter bubble by inspecting it and figuring out its element's classes.
Edit: since the +1 button is called within an iframe, what I described above won't work. What you could do instead is target the +1 div and set its opacity to 0, then place it on top of your own image. The div ID to target is
#___plusone_0
考虑到该按钮驻留在 iframe 中并且由于跨域限制,因此不太可能更改它。
Considering the button resides in an iframe and due to cross-domain restrictions, altering this is unlikely.
这是我为官方 google +1 代码使用自定义图标的解决方案
+1 按钮 - Google+平台 - Google 开发者
就像魅力一样工作
This is my solution for using a custom icon for the official google +1 code
+1 Button - Google+ Platform - Google Developers
Works like a charm
您现在应该使用它:https://plus.google.com/share?url=URL_HERE
You should use this now: https://plus.google.com/share?url=URL_HERE