Jcarousle - 在制作动画之前加载图像以防止出现白色空方块
我正在与 jCarousel 合作建立一个画廊。 我创建了一个脚本,每次单击数组中的下一个按钮时,该脚本都会将下一个图像加载到图库中。每次我单击“下一步”时,都会加载接下来的五张图像。这一切都非常好,但我的问题是,在加载图像之前我看到了空白
有趣的是,如果我添加一个警报,当我关闭它时,图像已经加载并且动画是完美的 - 就好像代码继续运行并且图像已加载 - 除了动画仅在警报结束后才开始已关闭。
2)我尝试将图像加载到一些不可见的缓存div,但当然我必须使其显示:无,并且同样,直到动画开始才加载图像(并且图像转为显示) :阻止...
这是我用来加载图像的行、事件和函数名称:
itemLoadCallback:{onBeforeAnimation:mycarousel_itemLoadCallback}
我知道这可能是输入和代码不足,但脚本变得很长,因此如果特定部分可能有用(或全部?),请告诉我......我不想使消息变得混乱:)
感谢您阅读本文, 严
I'm working on a gallery with jCarousel.
I've created a script that loads the next images to the gallery each time I click on the next button from an array. Each time I click next, the next five images are loaded. It all works really great, but my problem is that I see the empty
I tried two solutions :
1) add a delay to the animation - after the
The interesting thing is that if I add an alert, when I dismiss it the images are already loaded and the animation is perfect - as if the code keeps running and the images are loaded - except the animation starts only after the alert is closed.
2) I tried to load the images to some invisible caching div, but of course I have to make it display:none, and again the same, the images are not loaded until the animation starts (and images are turned to display: block ...
this is the line, event and function name I use to load the images:
itemLoadCallback: {onBeforeAnimation: mycarousel_itemLoadCallback}
I know this might be insufficient input and code, but the script became very long so if a specific part could be usefull (or all of it?) just let me know... I don't want to clutter the message :)
Thanks for reading this,
Yan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通过执行以下操作来完成此操作:
例如
注意:这不是完整的工作代码;为了清晰起见,对其进行了向下编辑。另外,请记住,我传递给
addItems()
的数据是 json 对象数组,每个对象都包含一个 ImageUrl 属性。I accomplished this by doing the following:
e.g.
Note: this isn't complete working code; it was edited to down for clarity. Also, keep in mind, the data I'm passing in to
addItems()
is array of json objects, each of which contains an ImageUrl property.试试这个 http://elouai.com/javascript-preload-images.php
干杯。
Try this http://elouai.com/javascript-preload-images.php
Cheers.