2012-03-05 25 views
1

基本上,我需要重新创建页面:http://www.facebook.com/me/friends朋友与大小的图片

不过:因为不是所有的图片是真实的广场,我需要得到他们的尺寸,以便使用CSS和隐藏的溢出(就像Facebook的裁剪他们基本上)。我知道有一种方法来检索方形图像,但它们的大小是50x50像素(我想要大一些)。

我想FQL能做到这一点,也许会开始是这样的:从JavaScript

fql?q=SELECT name, pic_big FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) 

回答

1

你可以得到图像尺寸,然后强制在一个固定的高度/宽度DIV他们定位为背景图像。图像加载后,您可以通过javascript获取宽度的高度。

IMG onload事件看:http://www.w3schools.com/jsref/event_img_onload.asp

这里就是你要做的

<img onload="redoImage(this)" src="<%=user["pic_big"]%>" id="pic1">

或通过JS

var img=new Image(); 
img.onload = redoImage(); 
img.src="<%=user["pic_big"]%>"; 

那么这才是真正的地方,图片显示了和你”用适当的偏移量设置它的背景图像以使图像正确显示。花点时间计算出如何获得偏移x或偏移y。

<div id="pic1-holder" style="width:120px; height:120px;">&nbsp;</div>

function redoImage(this) { 
    var xOffset = computeXoffset(this.width, 120); 
    var yOffset = computeYoffset(this.height, 120); 
    // now set the background image of the div 
    // and the offset of that background image 
}; 

我的生产代码,奇妙做到这一点。快乐的编码。

+1

非常棒!谢谢! – MonsieurNinja 2012-03-07 09:56:01