jQuery循环pagerAnchorBuilder [英] jQuery Cycle pagerAnchorBuilder

查看:109
本文介绍了jQuery循环pagerAnchorBuilder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Cycle插件在新闻转播器中使用.这意味着我正在使用Div来填充幻灯片而不是图像.

I'm using the Cycle plugin for use in a news-rotator. This means I'm using Div's to populate the slides instead of images.

我的最终目标是制作一个寻呼机,而不是通常的1、2、3、4等.它改为返回幻灯片中的第一个H3标签.

My ultimate goal is to make a pager where instead of the usual 1, 2, 3, 4, etc. - it instead returns the first H3 tag in the slide.

我知道这可能是一个较小的选择问题,但是到目前为止,这是我正在使用的内容:

I know this probably a minor selection issue, but here's what I'm using so far:

$('#scroll_wrap').cycle({
        fx: 'fade',
        pager: '#pager',
        pagerAnchorBuilder: function(idx, slide) { 
                return '<li><a href="#">' + slide.children("h3").textContent + '</a></li>';
        }

我也尝试过这样的事情:

I've also tried something like this:

    $('#scroll_wrap').cycle({
    fx: 'fade',
    pager: '#pager',
    pagerAnchorBuilder: function(idx, slide) { 
            var h3 = $('div',slide).children('h3');
            return '<li><a href="#">' + slide.h3 + '</a></li>';
    }

您可能会说,我仍处于起步阶段. :/

As you can probably tell, I'm still a fledgling. :/

有人可以帮助我解决问题吗?

Can anyone help me out with the seleciton??

推荐答案

将pagerAnchorBuilder函数中的一行更改为此:

Change the one line in your pagerAnchorBuilder function to this:

return '<li><a href="#">' + jQuery(slide).children("h3").eq(0).text() + '</a></li>';

需要更改三件事:

幻灯片=> jQuery(幻灯片)
因为jQuery除非您告知,否则不会使用其辅助函数扩展元素.这是jQuery的不幸副作用,它没有扩展本机的原型(例如Element).这意味着您必须使用jQuery(x)将代码中的所有第三件事都包装起来.

slide => jQuery(slide)
Because jQuery doesn't extend elements with its helper functions unless you tell it to. This is an unfortunate side-effect of jQuery not extending the prototypes of natives (like Element). It means you have to wrap every third thing in your code with jQuery(x).

children("h3")=> children("h3").eq(0)
由于选择器返回匹配的对象数组,因此您应在选择器之后获取第一个对象,否则链中的以下方法调用将作用于元素集. jQuery应该提供诸如.firstChild("h3")之类的东西.

children("h3") => children("h3").eq(0)
Because selectors return arrays of objects matched, you should grab the first one after you do the selector otherwise the following method call in the chain will act on the set of elements. Jquery should offer things like .firstChild("h3").

textContent => .text()
textContent是mozilla的东西,在某些浏览器上无法使用.在此处使用jQuery的.text()方法.在这种情况下,jQuery没有做错任何事情.

textContent => .text()
textContent is a mozilla thing, and wont work on some browsers. Use jQuery's .text() method here. In this case jQuery did nothing wrong.

这篇关于jQuery循环pagerAnchorBuilder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆