所以,这是不可能的,这将解决您的问题,因为你似乎有足够能力知道如何做到这一点,发布到实际对问题进行评估没有真正的代码,我不能找出你正在使用的是哪个Facebook API,但是,你不能仅仅捕获点击事件和iframe的宽度,不管它是什么,只是比较偏移量?喜欢的东西 -
$("#social-container").click(function(e){
var facebookSelector = $(iframe selector here);
var iframeHeight = facebookSelector.height();
var iframeWidth = facebookSelector.width();
var winHeight = $(window).height();
var winWidth = $(window).width();
if (e.clientY && e.clientX){
//Set the top based on where mouse click occured
if (e.clientY > (winHeight-iframeHeight)){
facebookSelector[0].style.top = winHeight-iframeHeight + "px";
}
else {
facebookSelector.style.top = e.clientY + "px";
}
//Set the left based on where mouse click occured
if (e.clientX > (winWidth-iframeWidth)){
facebookSelector[0].style.left = winWidth-iframeWidth + "px";
}
else {
facebookSelector[0].style.left = e.clientX + "px";
}
}
}
上面的例子少verbose-
$("#social-container").click(function(e){
var facebookSelector = $(iframe selector here);
var h = $(window).height() - facebookSelector.height();
var w = $(window).width() - facebookSelector.width();
if (e.clientY && e.clientX){
//Set the top based on where mouse click occured
facebookSelector[0].style.top = (e.clientY > h) ? h + "px" : e.clientY + "px";
//Set the left based on where mouse click occured
facebookSelector[0].style.left = (e.clientX > w) ? winWidth-iframeWidth + "px" : e.clientX + "px";
}
}
你也可以使用像按钮,而不是点击位置的Facebook的位置(你想也好,真的)。
注意事项和附录:
1。如果您的iframe的id(或任何其他内容)由Facebook动态生成,并且您无法控制它,那么这将不会如此轻松。
2.如果Like按钮位于iframe中,防止事件冒泡到您的容器。
3.此示例目前需要jQuery。
4.您的iframe(或其他)必须是position: absolute
或position: fixed
你真的希望得到没有任何代码的帮助吗? – Jawad
发布一个显示问题的URL,我会尽力为您提供一个可行的解决方案。 –
@Jawed,这是Facebook的“赞”按钮,它作为一个iFrame进来...你期待什么代码?你想要我的容器? '