简体   繁体   English

向fotorama img标签添加额外数据

[英]adding extra data into fotorama img tag

I'm using http://fotorama.io/ to display gallery, with thumbnails option. 我正在使用http://fotorama.io/来显示带有缩略图选项的画廊。 I would like to add some extra data into img tag, but fotorama seems to remove it. 我想在img标签中添加一些额外的数据,但是fotorama似乎将其删除。 Here is my code: 这是我的代码:

  <div class="fotorama"
       data-nav="thumbs"
       data-allowfullscreen="native"
       data-thumbwidth="150"
       data-thumbheight="118"
       data-thumbmargin="20"
       >
    {{#photos}}
      <a href="{{url}}" data-thumb="{{thumbnail}}" data-extradata="{{somedata}}"></a>
    {{/photos}}
  </div>

{{#photos}}{{/photos}} is just Handlebars.js loop. {{#photos}} {{/ photos}}只是Handlebars.js循环。

Any suggestions how could I add some data into image, to access it later from javascript? 有什么建议我如何将一些数据添加到图像中,以便以后通过javascript访问它?

there is an event indicating that fotorama is ready. 有一个事件表明fotorama已经准备好。 Callback method has second parameter in which there is an object with data: 回调方法具有第二个参数,其中存在一个带有数据的对象:

$('.fotorama').on('fotorama:ready', function (e, fotorama, extra){
  console.log(fotorama.data[index].extradata);
});

PD: Edited for fixed parentheses PD:针对固定括号进行了编辑

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM