在Google评论脚本中将像素更改为百分比

时间:2016-04-23 00:19:43

标签: javascript html css html5 css3

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

在我看来,它看起来非常好,效果很好,并且可以整合到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 个答案:

答案 0 :(得分: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>