【问题标题】:Featherlight Image Count Index/Total [Indexing Error]Featherlight Image Count Index/Total [索引错误]
【发布时间】:2020-04-09 00:34:18
【问题描述】:

我正在尝试在 Featherlight Gallery 中添加图像计数。 示例:图片 1 of 6(图片旁边/下方的某处)

$.featherlightGallery.prototype.afterContent = function(){
    var object = this.$instance,
        target = this.$currentTarget,
        parent = target.parent(),
        caption = parent.find('.wp-caption-text'),
        galParent = target.parents('.gallery-item'),
        jetParent = target.parents('.tiled-gallery-item');

    $('<div class="count">Image ' + (currentNavigation() + 1)+' of ' + slides().length + '</div>').html(object.find('.featherlight-content'));

    if (0 !== galParent.length) {
        caption = galParent.find('.wp-caption-text');
    } else if (0 !== jetParent.length) {
        caption = jetParent.find('.tiled-gallery-caption');
    }
    object.find('.caption').remove();
    if (0 !== caption.length) {
        $('<div class="caption">').text(caption.text()).appendTo(object.find('.featherlight-content'));
    }
}

它让我返回错误:currentNavigation is not defined

【问题讨论】:

    标签: featherlight.js featherlight


    【解决方案1】:

    您需要致电this.currentNavigation()

    【讨论】:

    • 我试过这些调用 $.featherlightGallery.prototype.afterContent = function(featherlight,current,currentNavigation,next,previous,slides){ ,现在它说 currentNavigation 不是一个函数。另外,我似乎无法将 div 附加到 ('.featherlight-content')
    • 我终于明白了!谢谢,马克! :D
    • 这没有提供问题的答案。要批评或要求作者澄清,请在他们的帖子下方留下评论。 - From Review
    • @Notabug:我的回答确实回答了这个问题,即要获取当前图像的索引,您需要调用this.currentNavigation(),而不是currentNavigation(),如他发布的代码。
    【解决方案2】:

    天哪!我得到了它!我猜那是侥幸!在尝试了几个概率之后,这是最终的答案。我希望有人会觉得这很有用;D

    $.featherlightGallery.prototype.afterContent = function(){
        var object = this.$instance,
            target = this.$currentTarget,
            parent = target.parent(),
            caption = parent.find('.wp-caption-text'),
            galParent = target.parents('.gallery-item'),
            jetParent = target.parents('.tiled-gallery-item');
    
        var sc = $('<div class="count">Image ' + (this.currentNavigation() + 1) + ' of ' + this.slides().length + '</div>');
        sc.appendTo(object.find('.featherlight-content'));
    
        object.find('.count').remove();
        if (0 !== sc.length) {
            sc.appendTo(object.find('.featherlight-content'));
        }
        if (0 !== galParent.length) {
            caption = galParent.find('.wp-caption-text');
        } else if (0 !== jetParent.length) {
            caption = jetParent.find('.tiled-gallery-caption');
        }
        object.find('.caption').remove();
        if (0 !== caption.length) {
            $('<div class="caption">').text(caption.text()).appendTo(object.find('.featherlight-content'));
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-08-22
      • 1970-01-01
      • 1970-01-01
      • 2020-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多