Fancybox - Ajax 图片库
我有一个自定义图像库,它用缩略图填充 div,每个缩略图都包含在一个 fancybox 组中。
当您单击一个(它在 fancybox 中打开)时,您可以按“上一张”/“下一张”在第一“页面”上的图像之间循环。要在页面之间移动,您必须关闭 fancybox 并更改页面,然后打开新的缩略图。这组新照片是通过ajax 检索的。
为了准确地向你展示我在说什么 http://www.speedcountry.com/mSpeed323/Mazda_MAZDASPEED3
如何使用 fancybox 切换页面并加载下一组图像?
I have a custom image gallery which populates a div with thumbnails, each contained in a fancybox group.
When you click one (it opens in fancybox) and you can press Prev/Next to cycle between images on the first "page". To move between pages, you have to close fancybox and change pages then open a new thumbnail. This new set of photos is retrieved via ajax.
To show you exactly what I'm talking about,
http://www.speedcountry.com/mSpeed323/Mazda_MAZDASPEED3
How can I use fancybox to switch pages and load the next set of images?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
FancyBox 中似乎没有任何内部方法,因此您必须修改插件。我冒昧地做了一个小改动并发布了一个 演示 - 在演示中,打开任何FancyBox 弹出窗口中的图像,然后按键盘上的 Enter。它将把所有图像加载到图库中并从第一个开始。
修改第887行,然后在892之前插入一行:
所以,基本上添加“array”作为函数参数,然后添加
if (array)...
行。要使用它,只需在 FancyBox 打开时调用 pos 函数即可。这是演示中的代码:
*注意:最初我只是使用
$('a[id]')
并且它包含精美框中的图像。更新:就像你说的,你正在使用ajax加载更多图像......我猜你只是得到一个图像网址列表。从 url 开始,您需要形成这些图像并将其添加到页面的隐藏区域中:
然后您可以将 jquery 对象数组
$('#ajax-content img')
添加到$.fancybox.pos
函数作为第二个参数,并从第一个图像(零)开始更新#2:我将上面的 HTML 包装在链接和 jQuery 选择器中我发现如果你想包含图像标题,这是必要的。
It doesn't appear there are any internal methods in FancyBox, so you'll have to modify the plugin. I took the liberty of making a minor change and posting a demo - in the demo, open any image in a FancyBox popup, then press Enter on the keyboard. It will load all of the images into the gallery and start from the first.
Modified line 887, then insert a line before 892:
So, basically add "array" as a function parameter, then add the
if (array)...
line.To use it, just call the
pos
function while FancyBox is open. This is the code from the demo:*Note: Initially I just used
$('a[id]')
and it included the image that was inside fancy box.Update: So like you said, you are loading in more images using ajax... I'm guessing you are just getting a list of image urls. Starting with a url, you will need to form and add these images to the page in a hidden area:
Then you can make an array of jquery objects
$('#ajax-content img')
to the$.fancybox.pos
function as a second paramter, and start with the first image (the zero)Update #2: I wrapped the above HTML in links and the jQuery selector after I found that it is necessary if you want to include an image caption.
我在此处的答案中发布了一些有用的 FancyBox 链接。请检查它们。
如果您觉得没有用,请纠正我。
同时,如果实现有任何问题,请贴出代码。
谢谢。
I have posted some useful links of FancyBox in my answers here. Please check them.
If you don't find it useful, please correct me.
Meanwhile, if there is any issue with the implementation, please post code.
Thank you.
刚刚在
prepGallery()
末尾添加了$("#profileGallery .vehiclePictures:first").click()
。因此,在您的 AJAX 调用之后,它会自动“单击”照片。Just added
$("#profileGallery .vehiclePictures:first").click()
at the end ofprepGallery()
. So after your AJAX call, it will automatically "click" the photo.