javascript - 从 lightGallery 插件获取 data-src
问题描述
我正在使用 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',但我无法弄清楚我应该如何使用它?
任何帮助,将不胜感激。
解决方案
试试下面的代码
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);
推荐阅读
- node.js - .npmrc 中以双斜杠“//”开头的行是什么意思?
- excel - Excel VBA - 过滤动态范围内的行
- javascript - 仅使用 chrome.storage.local.set 更新指定元素
- c++ - 计算 FreeType 字形渲染的位置?
- javascript - 使用 JavaScript 将数据写入文本文件
- azure-data-explorer - 查找多个字段组合的最大计数
- powerbi - 面向列的矩阵中的一般每月总计
- mysql - 使用 gcc 的 C 代码无法链接到 mysql 标头?
- google-app-maker - 如何浏览到加载到 Google AppMaker 表中的数据源中的下一页
- kibana - Filebeat Nginx 捕获 vhost