问题描述
例如,我可以从图形 api 中检索 facebook 封面来源和 offset_y -
https://graph.facebook.com/Inna
我明白了 -
封面":{"cover_id": "10151356812150381",来源":http://sphotos.xx.fbcdn.net/hphotos-snc7/s720x720/419277_10151356812150381_302056140380_23114100_97822830_n.jpg"偏移_y":54}
但是当我查看实际的 facebook 页面时,我看到顶部偏移是 -135px.这是如何从 54 计算出来的?
我想在我的网站上显示某人的封面照片,偏移量与 Facebook 相同.所以我基本上是在做 -
CSS -
.ed .ed-cover{高度:315px;溢出:隐藏;位置:相对;}.ed .ed-cover img{宽度:100%;位置:绝对;}
JS -
FB.api(artist, function (data) {$('.ed-cover img').attr('src', data.cover.source).css("top", -1 * data.cover.offset_y);});
但是这里top"属性的 CSS 偏移是不正确的,因为我返回 54 并且实际偏移是 -135px;
是的,实际上我自己找到了答案.facebook 发送的偏移量是百分比!
以下工作完美 -
FB.api(artist, function (data) {$('.ed-cover img').attr('src', data.cover.source).css("top", (-1 * data.cover.offset_y) + '%');});
I can retrieve facebook cover source and offset_y from graph api for example -
https://graph.facebook.com/Inna
I get this -
"cover": {
"cover_id": "10151356812150381",
"source": "http://sphotos.xx.fbcdn.net/hphotos-snc7/s720x720/419277_10151356812150381_302056140380_23114100_97822830_n.jpg",
"offset_y": 54
}
But when i look at the actual facebook page for this, i see the top offset is -135px.How is that calculated from 54?
I want to display someones cover photo on my website, with the same offset as facebook. So I am basically doing -
<div class="ed-cover">
<img src=""/>
</div>
CSS -
.ed .ed-cover
{
height:315px;
overflow:hidden;
position:relative;
}
.ed .ed-cover img
{
width:100%;
position:absolute;
}
JS -
FB.api(artist, function (data) {
$('.ed-cover img').attr('src', data.cover.source).css("top", -1 * data.cover.offset_y);
});
But the CSS offset here for the "top" property is incorrect as i get back 54 and the real offset is -135px;
Yes i actually found the answer myself. The offset that facebook sends is in percentage!
The following worked perfectly -
FB.api(artist, function (data) {
$('.ed-cover img').attr('src', data.cover.source)
.css("top", (-1 * data.cover.offset_y) + '%');
});
这篇关于如何计算 Facebook 图 api 覆盖 offset_y 到像素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!