Fancybox 画廊与 jQuery 的 .live()
我正在尝试显示一个 Fancybox 画廊,其中包含通过 JSON 加载的数据。加载并附加新的 HTML 后,我能够正确加载 Fancybox。但是,当我附加 rel="somegroup" 时,图库功能不起作用,并且我无法迭代 Fancybox 中的图像组。
这是我的 fancybox 调用:
$('.fancyness').live('click', function(){
$.fancybox(this, {
'width' : 'auto',
'height' : 'auto',
'titleShow' : true,
'titlePosition' : 'over'
});
return false;
});
这是图像的样子:
html += '<li><a class="fancyness" rel="group" href="' + full + '" title="'+ title +'">';
html += '<img title="' + item.title + '" src="' + thumbnail + '" alt="' + item.title + '" /></a></li>';
如果我不使用 .live,则 gallery (rel) 函数将正常工作,但不能在此数据上工作,因为这是使用 JSON 加载的。
有人有什么想法吗?我没有运气找到其他有类似问题的人。
谢谢。
I am trying to display a Fancybox gallery with data that gets loaded via JSON. I was able to get the Fancybox to load properly after I load in and append the new HTML. However, when I attached rel="somegroup" the gallery functionality doesn't work and I cannot iterate through the group of images from the Fancybox.
Here's my fancybox call:
$('.fancyness').live('click', function(){
$.fancybox(this, {
'width' : 'auto',
'height' : 'auto',
'titleShow' : true,
'titlePosition' : 'over'
});
return false;
});
And here is what the images look like:
html += '<li><a class="fancyness" rel="group" href="' + full + '" title="'+ title +'">';
html += '<img title="' + item.title + '" src="' + thumbnail + '" alt="' + item.title + '" /></a></li>';
If I don't use .live the gallery (rel) function will work correctly but not on this data because this is being loaded in with JSON.
Does anyone have any ideas? I haven't had much luck finding anyone else with a similar issue.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有类似的问题。如果您感兴趣的话,我在这里发现了一些看起来很有前途的东西。那里似乎对大多数人有效的解决方案是编辑 fancybox 代码,将 .bind 替换为 .live。不过,我无法让它适用于图片画廊。另一个建议(评论14)确实有效(并且不需要对 fanybox 进行任何混乱)。尝试一下,
如果您查看链接中的注释 14,您会注意到这里的第二个选择器只是该注释中的
$(this)
。这对于单个图像来说很好,但如果您使用图像库,您希望 fancybox 在所有图像上启动,而不仅仅是您将鼠标悬停然后单击的图像(仅供参考,我还包括了焦点事件,因此如果您在缩略图上按键盘选项卡并按 Enter 键,图像库仍然会打开)。如果将
"mouseover focus"
替换为"click"
,您会发现单击拇指只会触发 fancybox 插件。然后,您需要再次单击才能实际启动图库 - 因此会出现“鼠标悬停焦点”
事件。I had a similar problem. I found something which looked promising over here if you are interested. The solution over there that seemed to work for most was to edit the fancybox code, replacing .bind with .live. I couldn't get that to work for image galleries, though. Another suggestion (comment 14) did work (and doesn't require any messing with fanybox). Try,
If you look at comment 14 from the link you'll note that what is the second selector here is simply
$(this)
in that comment. That is fine for single images, but if you are using an image gallery you want fancybox to launch on all the images, not just the one you mouseover'd and then clicked (FYI I also included the focus event so the image gallery still opens if you keyboard-tab over a thumbnail and hit enter).If you replace
"mouseover focus"
with"click"
you will find that clicking on a thumb only fires the fancybox plugin. You then need to click a second time to actually launch your gallery - hence the"mouseover focus"
events, instead.让我困扰的是,在上述解决方案中,每次将鼠标移到某个 fancybox 元素上时,fancybox 函数都会被触发,所以我写了这个,它可以工作,但不会触发任何内容,除非您单击它。
对于旧的 jQuery
It bothered me how in the above solution the fancybox function would be triggered every time you move your mouse over some fancybox element, so I wrote this, which works but does not trigger anything unless you click on it.
for old jQuery