!!!如果任何人現在可以回答這個問題,我會等待賞金期結束,並在獎勵之前將其提高到150。 (童子軍榮譽!)!!!Facebook API封面圖片在背景位置屬性中的偏移
我環顧四周,但不能找到這個問題的答案:
我從FB API獲取事件封面圖片,並且還存儲offset_x和offset_y值。然後我放置圖像作爲CSS背景圖像是這樣的:
CSS
.event-image {
margin-bottom: 30px;
width: auto;
width: 500px;
height: 178px;
max-width: 100%;
min-width: 300px;
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
outline: none;
}
高度/寬度是基於被Facebook使用的確切比率:2,8:1
HTML
<div class="event-image" style="background-image: url([url of img]); background-position: [offset_x]% [offset_y]%;" >
(我確實有一些內在的邏輯,只有增加的背景positio n財產,如果在fb api中有一組。)
問題是,這隻能工作90%的時間。大約10%的圖像略微未對齊。通常只有幾個百分點:-(
下面是一個例子。
.event-image {
margin-bottom: 30px;
width: auto;
width: 500px;
height: 178px;
max-width: 100%;
min-width: 300px;
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
outline: none;
}
<div class="event-image" style="background-image: url(https://scontent.xx.fbcdn.net/t31.0-0/p180x540/14566476_1295215523823549_1334771895810946224_o.jpg); background-position: 0% 50%; "> \t </div>
<!-- Offsets are taken directly from API -->
現在這裏是actual event
你可以看到,實際上偏移會完美的46% - 那爲什麼fb給50%?
我能找到的最多的信息是pixel calculations,但考慮到我正在使用百分比,這沒有用。
編輯
新頒佈實施ELFAN的解決方案:
Here is an event在FB裏的圖像具有offset_x在-7px實際的FB - 但根據API中,offset_x = 50%
{
"cover": {
"offset_x": 50,
"offset_y": 0,
"source": "https://scontent.xx.fbcdn.net/t31.0-8/s720x720/14681104_1307094859330152_7540791723420117074_o.jpg",
"id": "1307094859330152"
},
"id": "544220282434185"
}
因此,使用計算500px (width of my image) * offset_x % = 250px
我在做什麼錯:-)
我也注意到,有一些事件有瘋狂的偏移量,例如1800。根據fb文檔,它應該在0-100之間。
謝謝!這絕對是正確的答案:-) - 我會讓賞金到期,然後升到150,並儘快給予獎勵。 – asimovwasright
感謝賞金:)作爲獎金,我用更多的解釋更新了我的答案,關於46%。 – elfan
我遇到了一些麻煩實施這個解決方案,你能解釋我哪裏去錯了 - 我將編輯我的問題與新問題。 – asimovwasright