jcarousel问题
我正在尝试做我看到很多人尝试使用 jcarousel 做的事情,即我想清除它并动态地重新填充它。我似乎找到了一种方法来完全清除 DOM 中的空 li 项目(常见的抱怨),但我似乎无法从远程文件添加项目。这是我的代码:
$(function() {
$('#mycarousel').jcarousel({
initCallback:carousel_callback
});
function carousel_callback(carousel){
$('#live-edge-large img').click(function(){
carousel.size(0); // sets size to 0
$('#mycarousel').empty(); // empties ul
carousel.reset(); //clears DOM of li's
$.get('ajax/xml-content.php',
{
first: carousel.first,
last: carousel.last
},
function(data) {
mycarousel_itemAddCallback(carousel,carousel.first,carousel.last,data);
},"xml"
);
});
};
function mycarousel_itemAddCallback(carousel,first,last,data) {
carousel.size(parseInt(jQuery('total', xml).text()));
$('image',xml).each(function(i) {
carousel.add(first+i, mycarousel_getItemHTML($(this).text()));
});
};
function mycarousel_getItemHTML(url)
{
return'<img src="' + url + '" width="128" height="95" alt="" />';
};
});
代码一直有效,直到这一行:
carousel.size(parseInt(jQuery('total', xml).text()));
这是我的带有 xml 的 php 文件:
<?php
header ("Content-Type:text/xml");
?>
<data>
<total>3</total>
<image>images/thumbs/test-9-thumb.jpg</image>
<image>images/thumbs/test-2-thumb.jpg</image>
<image>images/thumbs/test-3-thumb.jpg</image>
</data>
不确定为什么我无法设置大小,然后将项目添加到轮播中,也许无法以这种方式重置大小?有什么想法吗?非常感谢。
I'm trying to do what I've seen many people try to do with jcarousel, which is, I'd like clear it and refill it dynamically. I seem to have found a way to entirely clear the DOM of empty li items (a common complaint) but I then cannot seem to add items from a remote file. Here's my code:
$(function() {
$('#mycarousel').jcarousel({
initCallback:carousel_callback
});
function carousel_callback(carousel){
$('#live-edge-large img').click(function(){
carousel.size(0); // sets size to 0
$('#mycarousel').empty(); // empties ul
carousel.reset(); //clears DOM of li's
$.get('ajax/xml-content.php',
{
first: carousel.first,
last: carousel.last
},
function(data) {
mycarousel_itemAddCallback(carousel,carousel.first,carousel.last,data);
},"xml"
);
});
};
function mycarousel_itemAddCallback(carousel,first,last,data) {
carousel.size(parseInt(jQuery('total', xml).text()));
$('image',xml).each(function(i) {
carousel.add(first+i, mycarousel_getItemHTML($(this).text()));
});
};
function mycarousel_getItemHTML(url)
{
return'<img src="' + url + '" width="128" height="95" alt="" />';
};
});
The code is working until this line:
carousel.size(parseInt(jQuery('total', xml).text()));
Here's my php file with the xml:
<?php
header ("Content-Type:text/xml");
?>
<data>
<total>3</total>
<image>images/thumbs/test-9-thumb.jpg</image>
<image>images/thumbs/test-2-thumb.jpg</image>
<image>images/thumbs/test-3-thumb.jpg</image>
</data>
Not sure why I can't set the size and then add items to the carousel, maybe the size can't be reset in this way? Any ideas? Thanks very much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的函数 mycarousel_itemAddCallback 中,将“xml”替换为“data”,它应该可以工作...
In your function mycarousel_itemAddCallback, replace 'xml' with 'data' and it should work...