简体   繁体   English

如何使用 backstretch 向图像幻灯片添加 alt 标签?

[英]How do I add alt tags to an image slideshow using backstretch?

I am trying to add alt tags to an image slideshow using backstretch, but my code below is not working.我正在尝试使用 backstretch 向图像幻灯片添加 alt 标签,但我下面的代码不起作用。

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src="js/min/jquery.backstretch-min.js"></script> 
<script>
    $.backstretch([
     { url: "img/hero/hero11.jpg", alt: "Some alt text" }, 
     { url: "img/hero/hero10.jpg", alt: "Some alt text 2" },
    ],  {duration: 2000, fade: 750});
  });
});

</script>

I added this to jquery.backstretch-min.js:我将此添加到 jquery.backstretch-min.js:

 $(document).ready(function() { $('.backstretch img').attr('alt', 'this is a purple background image'); });

And it works for the first image, but when the slideshow changes to the next image the alt tag goes away and never reloads.它适用于第一张图片,但是当幻灯片切换到下一张图片时,alt 标签消失并且永远不会重新加载。

reeljanie.com for reference, homepage slideshow needs to have alt tags. reeljanie.com作为参考,首页幻灯片需要有 alt 标签。

I am very new to js, thanks for your help.我对 js 很陌生,谢谢你的帮助。

You don't need to add anything to jquery.backstretch-min.js as it supports alt pretty well .你不需要向jquery.backstretch-min.js添加任何东西,因为它很好地支持alt

All you need is to fix your JS which has syntax error due to last two lines.您只需要修复由于最后两行而出现语法错误的 JS。
Just remove them:只需删除它们:

 $.backstretch([ { url: "https://picsum.photos/400/230", alt: "Some alt text" }, { url: "https://picsum.photos/400/230", alt: "Some alt text 2" }, ], {duration: 2000, fade: 750});
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-backstretch/2.1.18/jquery.backstretch.min.js"></script>

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

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