从lightGallery插件获取data-src

时间:2018-09-30 17:01:02

标签: javascript lightgallery

我正在使用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”,但我只是无法弄清楚应该如何使用它?

任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:0)

对于其他尝试解决此问题的人,我可以使用

来获得的索引

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

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

});

答案 1 :(得分:0)

试试下面的代码

<?php
/**
 * Disable payment gateway based on category.
 */
function ace_disable_payment_gateway_category( $gateways ) {
    // Categories that'll disable the payment gateway 
    $category_slugs = array( 'tobacco' );
    $category_ids = get_terms( array( 'taxonomy' => 'product_cat', 'slug' => $category_slugs, 'fields' => 'ids' ) );

    // Check each cart item for given category
    foreach ( WC()->cart->get_cart() as $item ) {
        $product = $item['data'];

        if ( $product && array_intersect( $category_ids, $product->get_category_ids() ) ) {
            unset( $gateways['ppec_paypal'] );
            break;
        }
    }

    return $gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'ace_disable_payment_gateway_category' );

你也可以替换这个函数 getHighResolutionScreenShots(src);