Fancybox 2 Custom Titles and Captions [from A(title) and IMG(alt]

后端 未结 4 1132
北海茫月
北海茫月 2020-12-21 05:58

I\'m trying to use title and \"captions\" from image alt tags with fancybox 2... for some reason I can\'t seem this to work...

    $(\'.fancybox\').fancybo         


        
相关标签:
4条回答
  • 2020-12-21 06:23

    I had a similar issue and ended up using a separate title tag for the thumbnail image. seems to work too, though not as dynamic.

    <a class="fancybox-print" data-fancybox-type="iframe"  title="Banking On Fun<p>Bank of America</p><br /><h3>For Bank of America we created print and in-store POP that told how home loans could turn dreams into reality.</h3>"href="template-print01.html"><img class="print" src="images/print.jpg" title="PRINT" alt=""/></a>
    
    0 讨论(0)
  • 2020-12-21 06:23

    If you use Fancybox with Angular ng-repeat you can do something like this, then it also works on text and you don't need an img tag or the img alt tag.

    title="<b>{{banner.fancyboxTitle}}</b><br>{{ banner.fancyboxParagraph }}"
    
    0 讨论(0)
  • 2020-12-21 06:44

    If I understood right, you want fancybox title as a combination of the title attribute in the a tag + the alt attribute in the img tag.

    If the above is correct, then having a html like

    <a class="fancybox" href="images/01.jpg" title="title anchor 01" ><img src="images/01t.jpg" alt="alt image 01" /></a>
    

    the fancybox title should say "title anchor 01 alt image 01"

    you do that with this script:

    $(document).ready(function() {
     $(".fancybox").fancybox({
      helpers : {
       title: { type: 'inside'}
      },
      afterLoad: function(){
       this.title = this.title + ' ' + $(this.element).find('img').attr('alt');
      }
     }); // fancybox
    }); // ready
    
    0 讨论(0)
  • 2020-12-21 06:47

    fiddling with debugger I found out this works:

    beforeShow : function() {
        var alt = this.element.children[0].alt;
        this.title = '<div class="new-title-title">' + alt + '</div>';
    },
    

    It is not the most elegant way, but it does what you (and I) want - get the ALT-value from the image.

    Regards, Paul

    0 讨论(0)
提交回复
热议问题