Use custom image for Google+1 button?

前端 未结 9 2183
粉色の甜心
粉色の甜心 2020-12-04 16:28

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

相关标签:
9条回答
  • 2020-12-04 16:51

    use opacity 0 to just make it invisible. Then use background for making it looks like what you want.

    <style>
    .my_custom_googleplusone{
    overflow: hidden;
    background: url(blahblah.png);
    }
    
    .my_custom_googleplusone:hover{
    background: url(blahblah2.png);
    }
    </style>
    
    <div class="my_custom_googleplusone">
      /// GOOGLE BUTTON WITH OPACITY OF 0 (and z-index 1 with absolute position);
    </div>
    
    0 讨论(0)
  • 2020-12-04 16:51

    This is my solution for using a custom icon for the official google +1 code

    +1 Button - Google+ Platform - Google Developers

    <style type="text/css">
    .google-plus-container { 
        position: absolute; /* just to position the container where i wante the button, position absoliute or relative is required*/ 
        right: 0; 
        top: 0; }
    .google-plus-iframe { 
        z-index: 1; 
        -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; 
        filter: alpha(opacity=0); 
        -moz-opacity: 0; 
        -khtml-opacity: 0; 
        opacity: 0; 
    }
    .google-plus-icon { 
        z-index: -1; 
        width: 32px; 
        height: 20px; 
        background: transparent url(http://static.educations.com/masterpages/pics/icons/social/gplusbw.png) no-repeat; 
        position: absolute; 
        top: 0; 
        right: 0; 
    }
    

    <div class="google-plus-container">
        <div class="google-plus-icon"></div>
        <div class="google-plus-iframe">
            <!-- Place this tag where you want the +1 button to render. -->
            <div class="g-plusone" data-size="medium" data-annotation="none"></div>
    
            <!-- Place this tag after the last +1 button tag. -->
            <script type="text/javascript">
                window.___gcfg = { lang: 'sv' };
    
                (function () {
                    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
                    po.src = 'https://apis.google.com/js/platform.js';
                    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
                })();
            </script>
        </div>
    </div>
    

    Works like a charm

    0 讨论(0)
  • 2020-12-04 16:53

    Finally! Found a nice solution to this problem. So simple and working :) Hope it helps you!

    <a href="https://plus.google.com/share?url=ADD_YOUR_URL" >
        <img src="path_to_your_image" alt="Google+" title="Google+"/>
    </a>
    

    Source: http://notesofgenius.com/how-develop-custom-google-plus-button/

    0 讨论(0)
  • 2020-12-04 17:00

    This is the official example from the google developers page:

    Also consider that the URL was updated.

    <a href="https://plus.google.com/share?url={URL}" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;">
      <img src="https://www.gstatic.com/images/icons/gplus-64.png" alt="Share on Google+"/>
    </a>
    
    0 讨论(0)
  • 2020-12-04 17:00

    If you were willing to use JavaScript, this will give a more official experience.

    HTML

    <a href="#" onclick="gPlus('http://example.com');" title="+1">
        <img src="custom-image.png" alt="Google+ +1 Button">
    </a>
    

    JavaScript

    function gPlus(url){
        window.open(
            'https://plus.google.com/share?url='+url,
            'popupwindow',
            'scrollbars=yes,width=800,height=400'
        ).focus();
        return false;
    }
    

    If you include that function globally, you can have such buttons all over the place without using multiple, lengthy, in-line onClicks.

    0 讨论(0)
  • 2020-12-04 17:00

    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 of a-sb-ig-e and a-sb-ig-ps-e and its parent is a <div> with a class of a-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

    0 讨论(0)
提交回复
热议问题