需要自定义jcarousel
我正在使用 jcarousel 构建滚动幻灯片,需要进行一些自定义。每当某个项目成为轮播中最后一个可见项目时,就会引用一个回调函数。
1. function mycarousel_itemLastInCallback(carousel, item, idx, state) {
display('Item #' + idx + ' is now the last item');
};
您可以在这里查看这是如何工作的。我想做的是更改此功能,以便显示屏仅显示当前图像的标题。我想将标题数据放在每个图像的 alt 标签中,但是我该如何访问它呢?我在函数内尝试过类似的操作:
var theimage=item.next(); var thetext=theimage.alt; display('thetext');
...这不起作用。我有点不知所措了!希望有人能启发我。
第二件事是,数据将自身附加到显示框中的先前数据。我需要每个标题来替换前一个标题。也不知道该怎么做。下面是控制这一点的 jcarousel 代码:
var row = 1; 功能显示{ // 登录到 Firebug (getfirebug.com)(如果可用) //if (window.console != undefined && typeof window.console.log == 'function') // 控制台.log(s);
if (row >= 1000)
var r = row;
else if (row >= 100)
var r = ' ' + row;
else if (row >= 10)
var r = ' ' + row;
else
var r = ' ' + row;
jQuery('#display').html(jQuery('#display').html() + r + ': ' + s + '<br />').get(0).scrollTop += 10000;
row++;
};
任何帮助都非常感谢!谢谢
I'm using jcarousel to build a scrolling slideshow and need to make some customizations. There is a callback function that is referenced whenever an item becomes the last visible item in the carousel.
1. function mycarousel_itemLastInCallback(carousel, item, idx, state) {
display('Item #' + idx + ' is now the last item');
};
You can see how this works here. What I would like to do is change this function so that the display shows just a caption of the current image. I would think to put the caption data in the alt tag of each image, but then how would I access it? I have tried something like this inside the function:
var theimage=item.next(); var thetext=theimage.alt; display('thetext');
...which didn't work. I'm in over my head here! Hopefully someone will enlighten me.
Second thing is, the data appends itself to the previous data in the display box. I need each caption to replace the previous caption. Not sure how to do that either. Here is the piece of jcarousel code that controls this:
var row = 1;
function display(s) {
// Log to Firebug (getfirebug.com) if available
//if (window.console != undefined && typeof window.console.log == 'function')
// console.log(s);
if (row >= 1000)
var r = row;
else if (row >= 100)
var r = ' ' + row;
else if (row >= 10)
var r = ' ' + row;
else
var r = ' ' + row;
jQuery('#display').html(jQuery('#display').html() + r + ': ' + s + '<br />').get(0).scrollTop += 10000;
row++;
};
Any help is super appreciated! Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您可能应该考虑使用 attr('alt') 来访问元素的属性。
之后,如果您查看 display() 方法,它会接受一个字符串。如果您需要它来显示名为 thetext 的变量,那么您的语法不正确,您需要类似以下内容:
var thetext= $(image).attr('alt');
显示(文本);
在您的示例中,该行:
var theimage=item.next();
意味着“theimage”可能已经是一个 jquery 包装的 html 元素。如果是这种情况:
var thetext= image.attr('alt');
显示(文本);
除此之外,我个人需要查看一个示例网页。在 jsfiddler.net 上设置一个页面,如果您仍然遇到困难,请将链接放回此处
Firstly, you probably should consider using attr('alt') to access attributes of an element.
After that, if you look at the display() method it accepts a string. If you need it to display the variable called thetext, then your syntax is incorrect, you want something like:
var thetext= $(image).attr('alt');
display(thetext);
In your sample the line:
var theimage=item.next();
means that 'theimage' is probably already a jquery wrapped html element. If that's the case:
var thetext= image.attr('alt');
display(thetext);
Beyond that, I'd personally need to see an example web page. Setup up a page on jsfiddler.net and put the link back here if you're still stuck