0

我正在使用 lightgallery 插件http://sachinchoolur.github.io/lightGallery/docs/api.html#attributes

我想在单击图像时获取 data-src 值。

基本的HTML如下

<div id="work-grid" class="grid wow fadeIn animated">
   <div class="ecp-thumbnail element-item landing" data-iframe="true"  data- 
    src="image/landingpages/alta_1.jpg">
   <img class="img-responsive img-thumbnail" 
   src="image/landingpages/thumb_alta_1.jpg" />
  </div>
</div>

我的javascript如下

var $workGrid = $("#work-grid");

$workGrid.lightGallery({
    mode: 'lg-fade',
    cssEasing: 'cubic-bezier(0.25, 0, 0.25, 1)',
    download: false,
     share: false,
     selector: 'this'
});

$workGrid.on('onBeforeOpen.lg', function (event, prevIndex, index) {
    alert($workGrid.data('src'));
});

但我似乎无法获得点击图像的 data-src 属性值。

我添加了选择器:'this',但我无法弄清楚我应该如何使用它?

任何帮助,将不胜感激。

4

2 回答 2

0

试试下面的代码

      var $lg =  $('#lightgallery').lightGallery({
            animateThumb: false,
            showThumbByDefault: false,
            controls:false
        });

        $lg.lightGallery();
        $lg.on('onBeforeSlide.lg',function(){
        let src =  $lg.data('lightGallery').$items.eq(0).data('src');
            getHighResolutionScreenShots(src);
        });

您也可以替换此功能 getHighResolutionScreenShots(src);

于 2020-12-20T21:21:04.977 回答
0

对于其他试图解决这个问题的人,我可以通过使用

$workGrid.on('onBeforeSlide.lg', function (event, index) {

alert($(".ecp-thumbnail").eq(index).attr('data-src'));

});

于 2018-10-01T14:26:01.140 回答