2016-04-23 87 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>