【问题标题】:Galleria: tigger which image to show onload or on clickGalleria:选择要在加载或点击时显示的图像
【发布时间】:2014-03-06 02:40:54
【问题描述】:

我正在使用 Galleria 插件来显示现有标记中无法更改的图像列表。

单击图像时,我正在加载一个灯箱,在灯箱内我有一个图像画廊。

我需要的是索引在初始旧标记中单击的图像,然后在画廊中触发相同的索引图像,或者将其作为活动图像加载。

触发或设置初始幻灯片加载是我遇到问题的地方?任何建议都会很棒。

类似于下面的标记:

<div class="productSlides">
<img alt="Conti Melamine Desk with Sharknose Edge.jpg" src="/Images/test1.jpg" />
<img alt="Conti-Melamine-Desk-with-Sharknose-Edge-FV.jpg" src="/Images/test2.jpg" />
<img alt="Conti-Glass-Desk-FV.jpg" src="/Images/test3.jpg" />
</div>
<div id="galleria"></div> 

<script type="text/javascript">
$( document ).ready(function() {
//Need to have two sets of images. The inital markup that can be clicked, and the same    images added to a Galleria tag to render the gallery.
$('.productSlides').clone().appendTo($('#galleria'));
});

Galleria.loadTheme('/UserUploadedJS/galleria.classic.js');
Galleria.run('#galleria', {

});

$( document ).ready(function() {

    $('.productSlides img').on('click', function(){ 
        var url = "#galleria"; // sets the link url as the target div of the lightbox
        $(this).colorbox({
             inline:true, // so it knows that it's looking for an internal href
             href:url, // tells it which content to show
             width:"70%",
             onOpen:function(){ //triggers a callback when the lightbox opens
                $(url).show(); //when the lightbox opens, show the content div
             },
             onCleanup:function(){
                $(url).hide(); //hides the content div when the lightbox closes
             }
        }); 
        var index = $(this).parent().find("img").index(this); //indexes the image cliked
        Galleria.ready(function() { //Attempt to show the same indexed image in the galleria
            var gallery = this;
            gallery.show(index);
        });



    });  


});
</script>

【问题讨论】:

    标签: javascript jquery image-gallery galleria


    【解决方案1】:

    首先在galleria的ready事件中获取选择的galleria图片索引

    Galleria.loadTheme('/UserUploadedJS/galleria.classic.js');
    Galleria.run('#galleria', 
    {
       show: selectedIndex
    });
    
    var selectedIndex=0;
     Galleria.ready(function() { //Attempt to show the same indexed image in the galleria
                var gallery = this;
               selectedIndex=index;
                //gallery.show(index);
            });
    

    我已经测试了代码在我最后的工作正常,添加你已经使用的脚本来获取索引。

    【讨论】:

      【解决方案2】:

      我编辑了脚本以获得我想要的。也许它对你也有用。

      我知道现在回答这个问题为时已晚,但它可以帮助其他人。

      就我而言,galeria.io 数据源已更新,可按需添加更多图像。 然后我打这个电话:

      Galleria.get(0).load(dataUpdated, undefined, { show: YOUR_POSITION });

      load : function( source, selector, config ) {
      
         //...
      
          // use the dataConfig set by option
          config = config || o.dataConfig;
      
          // Edited: 20150516 - Added by tuliocacalazans
          // Override show position
          // Added in line 3840, script version: galleria-1.4.2.js
          if (typeof config.show === 'number') {
              o.show = config.show; // o = this._options
          }
      
          //...
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-05-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-06-13
        • 2015-10-06
        • 1970-01-01
        相关资源
        最近更新 更多