2017-05-04 94 views
2

我创建了一个与lightgallerycycle2一起使用的相册,循环是一个轮播插件,lightgallery是一个灯箱画廊。为什么我的灯箱看不到这个属性?

,所以当我在旋转木马点击任何图像比它的形象在收藏打开,我想告诉你,一切都运行得非常好,直到你点击carousel.so任何类别我想麻烦你这个问题

点击任何类别后,如果您点击轮播图片上的图片并在控制台上看到错误,则灯箱不会打开。

插件给了我这个错误回报

[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]…:10 Uncaught TypeError: Cannot read property 's' of undefined 
    at new c ([email protected],[email protected],[email protected],[email protected],[email protected],[email protected]…:10) 
    at Function.<anonymous> ([email protected],[email protected],[email protected],[email protected],[email protected],[email protected]…:5) 
    at Function.each (jquery.min.js:2) 
    at b.build ([email protected],[email protected],[email protected],[email protected],[email protected],[email protected]…:5) 
    at HTMLDivElement.<anonymous> ([email protected],[email protected],[email protected],[email protected],[email protected],[email protected]…:5) 
    at HTMLDivElement.dispatch (jquery.min.js:3) 
    at HTMLDivElement.q.handle (jquery.min.js:3) 

enter image description here

两个星期我试图解决这个问题

please click to demo

$(document).ready(function() { 
 
    options = { 
 
    next: "#single-right", 
 
    log: false, 
 
    fx: "fade", 
 
    caption: ".cycle-caption", 
 
    captionTemplate: "{{title}}", 
 
    pauseOnHover: true, 
 
    pager: "#single-pager", 
 
    pagerTemplate: "<img class='lazyload' data-src='{{exthumbimage}}' width='70' height='70'>", 
 
    prev: "#single-left", 
 
    slides: "div[data-hidden='false']" 
 
    } 
 

 
    function generateSlider(opt) { 
 
    $("#myCarousel").cycle(opt); 
 
    } 
 

 
    generateSlider(options); 
 

 
    $('#myCarousel').lightGallery({ 
 
    selector: "div[data-hidden='false']", 
 
    exThumbImage: "data-exthumbimage", 
 
    loadYoutubeThumbnail: true, 
 
    youtubeThumbSize: 'default', 
 
    loadVimeoThumbnail: true, 
 
    vimeoThumbSize: 'thumbnail_medium', 
 
    }); 
 

 

 

 
    $("#filter li").on("click", function() { 
 
    var activeId = $(this).attr("id"); 
 
    if (activeId == "show-all") { 
 
     $(".item").attr("data-hidden", "false"); 
 
    } else { 
 
     $(".item").attr("data-hidden", "true"); 
 
     $("div[data-id = '" + activeId + "']").attr("data-hidden", "false"); 
 
    } 
 
    $("#myCarousel").cycle("destroy"); 
 
    options['pagerTemplate'] = "<img class='lazyload' data-src='{{children.0.src}}' width='70' height='70'>" 
 
    generateSlider(options); 
 
    return false; 
 
    }); 
 

 
});
.mySlideShow { 
 
    width: 700px; 
 
    position: relative; 
 
} 
 

 
.item img { 
 
    cursor: pointer; 
 
} 
 

 
#single-pager img { 
 
    margin: 3px; 
 
    cursor: pointer; 
 
    width: 60px; 
 
    height: 60px; 
 
} 
 

 
#filter { 
 
    position: absolute; 
 
    top: 0; 
 
    right: 10%; 
 
    z-index: 100; 
 
} 
 

 
#filter li { 
 
    display: inline-block; 
 
    background: rgba(0, 0, 0, .7); 
 
    color: #FFF; 
 
    cursor: pointer; 
 
    padding: 12px; 
 
} 
 

 
.cycle-caption { 
 
    position: absolute; 
 
    bottom: 14%; 
 
    left: 0; 
 
    padding: 12px; 
 
    background: rgba(0, 0, 0, .5); 
 
    color: #FFF; 
 
    text-align: center; 
 
    width: 100%; 
 
    z-index: 100; 
 
} 
 

 
div[data-hidden='true'] { 
 
    display: none; 
 
}
<link rel='stylesheet' href='https://cdn.jsdelivr.net/lightgallery/latest/css/lightgallery.css'> 
 

 
<div class="mySlideShow"> 
 
    <div id="myCarousel"> 
 
    <div class="item" data-src="http://images.freeimages.com/images/previews/49a/massive-gear-1255802.jpg" data-exthumbimage="http://images.freeimages.com/images/previews/fa7/my-ride-1552678.jpg" data-id="animals" data-hidden="false" data-title="image 1"> 
 
     <img class="lazyload" data-src="http://images.freeimages.com/images/previews/f7a/gear-1462890.jpg" /> 
 
    </div> 
 
    <div class="item" data-src="http://images.freeimages.com/images/previews/7ae/autos-1194364.jpg" data-exthumbimage="http://images.freeimages.com/images/previews/5f6/kaputtes-auto-1564173.jpg" data-id="sports" data-hidden="false" data-title="image 2"> 
 
     <img class="lazyload" data-src="http://images.freeimages.com/images/previews/20e/some-grill-1450817.jpg" /> 
 
    </div> 
 

 

 
    <div class="item" data-src="https://vimeo.com/1084537" data-exthumbimage="http://sachinchoolur.github.io/lightGallery/static/img/thumb-v-y-2.jpg" data-id="natural" data-hidden="false" data-title="this is the video"> 
 
     <img class="lazyload" data-src="http://images.freeimages.com/images/previews/c23/cat-1396828.jpg" /> 
 
    </div> 
 

 
    <div id="single-pager"> 
 
    </div> 
 
    </div> 
 
    <ul id="filter"> 
 
    <li id="animals">Animals</li> 
 
    <li id="sports">Sports</li> 
 
    <li id="natural">Natural</li> 
 
    <li id="show-all">All</li> 
 
    </ul> 
 
    <div class="cycle-caption"></div> 
 
</div> 
 

 
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script> 
 
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery.cycle2/2.1.6/jquery.cycle2.min.js'></script> 
 
<script src='https://cdn.jsdelivr.net/g/[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]'></script> 
 
<script src='https://cdnjs.cloudflare.com/ajax/libs/lazysizes/3.0.0/lazysizes.min.js'></script> 
 
<script src='https://f.vimeocdn.com/js/froogaloop2.min.js'></script>

+0

的codepen不会抛出错误。 – Phix

+0

@Pix点击全部,然后点击图片.... – gaetanoM

+0

嗨@Phix首先点击任何类别,例如自然,然后点击轮播图像 –

回答

4

当您筛选轮播项目时,会中断Lightbox实例。所以,你需要做的是:

  1. 摧毁收藏夹(如果你不这样做,当您尝试实例化一个新的话,会重新需要为它的运行帮手DOM元素,造成重复的ID和你灯箱将打破)。你需要调用
$('#myCarousel').data('lightGallery').destroy(true); 

没有true参数,这不是正确的破坏,它只是关闭(如果它是开放的)。

  1. 过滤滑块。
  2. 创建一个新灯箱。

工作例如:https://codepen.io/anon/pen/XRemwV

参考文件:http://sachinchoolur.github.io/lightGallery/docs/api.html#methods

+1

我很感谢你,所以我不能告诉你我是多么的高兴,它是伟大的,它运作得非常好 –

+0

我会再次创建看你的项目了解非常感谢你@Andrei –

相关问题