1

当我们打开图像滑块的页面时,我想首先显示图像及其文本。

这是我的演示:http ://codebins.com/bin/4ldqp9c/15

在这里,我显示所有 DOM 元素都已加载,但需要在打开页面时为我的滑块显示第一个图像及其文本。

所以我不明白如何为我的滑块加载我的初始图像,以便在所有 DOM 元素加载后启动它的功能。

4

1 回答 1

0

I believe the term is "bootstrapping". You want the first image to load in as the DOM is loading, and before your script sets up the image slider.

One way to achieve this is to actually put the image in as part of the DOM. So, instead of an empty src in your image tag, put an actual url. Same for title and description.

I assume you're going to be doing an ajax request for the XML you're building in your example. If that's the case, then you probably have no way of knowing what the first image is, which means you'll still need a script to load data.

The performance gains from having two scripts will probably be negligible, but if you take that approach, make sure you load the smaller script in the head section of your html, and the longer one at the end of your body.

于 2012-08-25T18:43:06.680 回答