我可以将操作绑定到特定的 Facebox 吗?
我想将一个函数绑定到特定facebox的关闭上?根据 facebox(at github) 上的有限文档,您可以执行类似的操作来绑定操作。
$(document).bind('close.facebox', function() {
//do stuff...
})
但这样做的问题是,它会将相同的操作绑定到页面上创建的所有 Facebox。
那么如何将不同的功能绑定到不同的facebox呢?我尝试了一些变体,但没有成功(可能是因为我还没有掌握 javascript 和 jQuery 的技能):
- 按照文档的建议绑定一个通用函数,并在函数中找出关闭的 Facebox 并执行所需的操作。
创建 Facebox 时获取句柄并使用它来绑定操作:
var fb = $.facebox('foo'); fb.bind('close.facebox', function() { ...do stuff ...})
直接在 Facebox 上调用绑定,如下所示:
$.facebox('foo').bind('close.facebox', function() { ...do stuff ...})
可能有更多我不记得的变体...
请帮助我理解如何我应该这样做(或者为什么我不应该尝试这样做)。
I want to bind a function to the closing of a specific facebox? According to the limited documentation at facebox(at github) you could do something like this to bind actions.
$(document).bind('close.facebox', function() {
//do stuff...
})
But the problem with this is that it will bind the same action to all faceboxes created on the page.
So how could I bind different functions to different faceboxes? I have tried a few variants without success (probably due to my not yet masterlevelskills of javascript and jQuery):
- Bind one general function as proposed by the documentation and in the function figure out what facebox was closed and do the wanted thing.
Get handle to facebox when created and use that to bind the action:
var fb = $.facebox('foo'); fb.bind('close.facebox', function() { ...do stuff ...})
Call bind on the facebox directly like:
$.facebox('foo').bind('close.facebox', function() { ...do stuff ...})
Probably more variants that I do not remember...
Please help me understand how I should do this (or why I should not try to do this).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
快速查看源代码后,我可以想到一个 hack (!) 来实现此功能:
facebox#close
方法。这是一个示例:
HTML:
JS:
在这里尝试一下:http://jsfiddle.net/SU3se/ 。
我相信该插件假设您不会在多个“不同”对象上使用它,并且由于您有时只能打开一个 Facebox,因此这“应该”不是问题。但我可以理解为什么有人可能想这样做。
请记住,我的解决方案是一个 hack,而且真的不是很漂亮。也许其他人可以想出更好的办法。
After a quick look at the source I can think of a hack (!) to make this work:
facebox#close
method with you own.Here's an example:
HTML:
JS:
Try it here: http://jsfiddle.net/SU3se/ .
I believe that the plugin makes the assumption that you'll not use it on multiple "different" objects and since you can have only one facebox open at times, this "should" not be an issue. But I can see why someone might want to do it nevertheless.
Please remember that my solution is a hack and really not very pretty. Maybe someone else can think of something better.