2016-04-23 90 views
0

是否可以在Google Plus评论脚本中将像素宽度值更改为百分比?在Google评论脚本中将像素更改为百分比

在我看来,它看起来非常好,工作得很好,以及融入到Google+。唯一的问题是,评论系统只能正式提供给Blogger,并且不明显如何将其添加到非博客网站。

这里是嵌入代码:

<script src="https://apis.google.com/js/plusone.js"></script> 
<div id="comments"></div> 
<script> 
gapi.comments.render('comments', { 
    href: window.location, 
    width: '624', 
    first_party_property: 'BLOGGER', 
    view_type: 'FILTERED_POSTMOD' 
}); 
</script> 

回答

1

如果该脚本将只接受在像素的特定值,而不是允许你指定一个百分比宽度,就可以计算出一个自己基于当前的视口宽度:

<script src="https://apis.google.com/js/plusone.js"></script> 
<div id="comments"></div> 
<script> 
gapi.comments.render('comments', { 
    href: window.location, 
    width: Math.round(window.innerWidth * 0.60), //for 60% 
    first_party_property: 'BLOGGER', 
    view_type: 'FILTERED_POSTMOD' 
}); 
</script>