如何在.galleria中添加替代文本?

Kau*_*hta 7 jquery

如何使用jquery.galleria.js在缩略图和大图像中添加替代文本?

$(window).load(function() {
      Galleria.loadTheme('http://www.bulogjatim.com/wp-content/themes/duotive-fortune/js/jquery.galleria.template.js');
      $("#galleria").galleria({
        width: 880,
        height: 439,
        transition: 'fadeslide'
      });
    );
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="galleria" class="galleria-wrapper">
  <a class="image-wrapper" href="http://veithen.github.io/images/icon-stackoverflow.svg">
    <img src="http://veithen.github.io/images/icon-stackoverflow.svg" />
  </a>
</div>
Run Code Online (Sandbox Code Playgroud)

And*_*ndy 8

您可以通过向标记添加data属性来实现img.

例如,data-layer会在图像上写一个标题.

用法示例:

    <img data-layer="my caption" src="image.jpg" >
Run Code Online (Sandbox Code Playgroud)

资料来源:http://galleria.io/docs/references/data/

编辑

要将altSEO优化的属性添加到galleria中的图像:

HTML: <img alt="My SEO optimized alt tag" src="image.jpg" >

要将它们添加到Galleria中的图像:

$(document).ready(function() {
  Galleria.loadTheme('/js/jquery.galleria.template.js');
  Galleria.run('.galleria');
  Galleria.ready(function() {
    this.bind('image', function(e) {
      // add alt to big image
      e.imageTarget.alt = e.galleriaData.original.alt;
    });
    this.bind('thumbnail', function(e) {
      // add alt to thumbnails image
      e.thumbTarget.alt = e.galleriaData.original.alt;
    });
  });
});
Run Code Online (Sandbox Code Playgroud)

我希望这能帮到你.

来源:http://support.galleria.io/discussions/problems/645-alt-tags-missing-from-folio-thumbnails

工作示例:http://embed.plnkr.co/nnTFw5SkUYeYZP6I9hqb/preview

  • 回答更新,感谢@gsinha报告我的示例代码中的错误并提供解决方案.

  • @Andy"alt"标签出现在活动图像上,但代码不是所有其他缩略图.我修复它:`Galleria.ready(function(){this.bind('image',function(e){e.imageTarget.alt ="my alt text";}); this.bind('thumbnail', function(e){e.thumbTarget.alt ="my alt text";});});` (3认同)