如何计算Facebook图形api盖offset_y到像素? [英] how to compute Facebook graph api cover offset_y to pixel?

查看:128
本文介绍了如何计算Facebook图形api盖offset_y到像素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以从graph api检索Facebook封面来源和offset_y,例如 -

I can retrieve facebook cover source and offset_y from graph api for example -

https://graph.facebook.com/Inna

我得到了 -

"cover": {
      "cover_id": "10151356812150381",
      "source": "http://sphotos.xx.fbcdn.net/hphotos-snc7/s720x720/419277_10151356812150381_302056140380_23114100_97822830_n.jpg",
      "offset_y": 54
   }

但是当我看到实际的facebook页面为此,我看到顶部偏移是-135px。
如何从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?

我想在我的网站上显示一些封面照片,与facebook的偏移相同。所以我基本上是 -

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);
                    });

但是这里的top属性的CSS偏移不正确,因为我回到54, offset is -135px;

But the CSS offset here for the "top" property is incorrect as i get back 54 and the real offset is -135px;

推荐答案

是的,我自己找到答案。 Facebook发送的偏移量是百分比!

Yes i actually found the answer myself. The offset that facebook sends is in percentage!

以下工作完美 -

    FB.api(artist, function (data) {
                            $('.ed-cover img').attr('src', data.cover.source)
.css("top", (-1 * data.cover.offset_y) + '%');
                        });

这篇关于如何计算Facebook图形api盖offset_y到像素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆