平滑div“画廊”带有 jQuery 选项卡
我正在寻找一种优雅且高效的解决方案,可以将其描述为 div
“画廊”。
目前我们正在使用 jQuery UI 选项卡并在服务器上预填充 div
。 用户只能看到活动的 div
,并且可以移至下一个或上一个选项卡。但是,由于列表现在包含 100 多个项目,我们希望切换到动态加载方法。
首先,我尝试将项目的 div
生成分离到 AJAX 调用,并使用内置的 Tabs AJAX 功能。然而,使用 jQuery UI Tabs AJAX 来回移动时的故障非常明显。加载选项卡后,它会被缓存,因此它会再次正常工作。
我现在有以下想法:
每次用户单击“下一步”时,以某种方式预取接下来的 5 个选项卡。
用户不太可能滚动得很快,而且我们可以接受快速滚动时出现的故障。我想要做的就是确保正常情况下,几个下一个选项卡在显示之前会被加载。这可以通过 jQuery Tab 实现吗?
在服务器上填充 JavaScript 数组并动态创建
div
。这是我正在研究的另一个可能的解决方案。我可以编写一个函数来通过 JavaScript 中保存的对象数据生成
div
。 JavaScript 可以由服务器生成。
哪个更合适?我错过了什么吗?
I'm looking for an elegant and efficient solution for something that can be described as a div
“gallery”.
Currently we're using jQuery UI tabs and prepopulate div
s on server. The user only sees the active div
and can move to next or previous tab. However, as the list now contains more than 100 items, we would like to switch to a dynamic loading approach.
At first, I tried to separate div
generation for an item to an AJAX call, and use builtin Tabs AJAX functionality. However, the glitch when moving back or forth with jQuery UI Tabs AJAX is very noticeable. When the tab has loaded, it gets cached so it works normal again.
I have the following ideas now:
Somehow prefetch next 5 tabs each time user clicks 'Next'.
The user isn't likely to scroll very fast, and we're okay with glitches in case of fast scrolling. All I want to do is to ensure that normally several next tabs are loaded before they get displayed. Is this possible with jQuery Tabs?
Populate a JavaScript array on server and create
div
s on the fly.This is another possible solution I'm looking into. I could've written a function to generate
div
by object data saved in JavaScript. The JavaScript could be generated by server.
Which is more appropriate? Am I missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,由于我没有得到回复,所以我选择了第二条路线,这似乎是一个很好的解决方案。
head
部分中的脚本使用服务器就地生成的 JSON 填充全局可见的items
数据列表。然后,在之前定义选项卡
div
的位置,我放置了一个脚本来动态生成它们:createTab
函数在单独的 JS 文件中定义,并管理创建 < code>div 和ul
的列表项:由于所有这些都发生在页面加载之前,因此我不必更改管理选项卡导航的代码。
当然,这还不能实现预取图像,但使其变得更容易,因为选项卡创建发生在一个地方并且变得更容易控制。
Okay, so as I got no responses I went with the second route and it seems like a good solution.
A script in the
head
section populates globally visibleitems
data list with JSON generated in-place by server.Then, where tabs
div
s were previously defined, I put a script to generate them on-the-fly:createTab
function is defined in a separate JS file and manages creatingdiv
and list items forul
:Since all of this happens before the page is loaded, I didn't have to change the code that manages tab navigation.
Of course, this doesn't yet enable prefetching images, but makes it much easier to do, as tab creation occurs at one place and it's become easier to control.