img に data-title 属性があるかどうかに応じて、カスタム Fotorama キャプションの表示を変えようとしています。現在、「未定義」として表示されていますが、その属性が存在しない場合は、その属性を完全に省略してください。if/else ステートメントを使用して、img 要素にその属性があるかどうかを確認しようとしましたが、役に立ちませんでした。ギャラリーを制約し、それに応じて画像のサイズを変更する必要があるため、「div」Fotorama アプローチを使用できません。
これは私のimgタグがどのように見えるかです:
<img src="images/whatever.jpg" data-caption="Brief description goes here." data-author="Additional description here" data-title="http://www.link.com" border="0">
これは、カスタム キャプション形式を作成するために使用しているコードです。
$('.fotorama')
.on('fotorama:show', function (e, fotorama) {
fotorama.$caption = fotorama.$caption || $(this).next('.example_blurb');
var activeFrame = fotorama.activeFrame;
fotorama.$caption.html(
'<p><em>' + activeFrame.caption + ' <a target="_blank" href="' + activeFrame.title + '">(link)</a></em></p><p>' + activeFrame.author + '</p>'
);
})
.fotorama();
これは、div に data-title 属性がない場合にキャプションを読みたい方法です。
'<p><em>' + activeFrame.caption + '</em></p><p>' + activeFrame.author + '</p>'
前もって感謝します!