Links within caption on Fancybox 2

你离开我真会死。 提交于 2019-12-06 16:01:20
JFK

For this html

<a class="fancybox" data-title-id="title-1" href="http://fancyapps.com/fancybox/demo/1_b.jpg"><img src="http://fancyapps.com/fancybox/demo/1_s.jpg" alt=""/></a>
<div id="title-1" class="hidden">
    This is 1st title. <a href="http://google.com">Some link</a>
</div>

<a class="fancybox" data-title-id="title-2" href="http://fancyapps.com/fancybox/demo/2_b.jpg"><img src="http://fancyapps.com/fancybox/demo/2_s.jpg" alt=""/></a>

<div id="title-2" class="hidden">
    This is <b>2nd title</b>. <a href="http://google.com">Some link</a>
</div>​

...set the helpers option and don't forget to separate each option with a comma like :

$(".fancybox")
    .attr('rel', 'gallery')
    .fancybox({
        openEffect  : 'fade',
        closeEffect : 'fade',
        nextEffect  : 'fade',
        prevEffect  : 'fade',
        helpers : {
                title : {
                    type : 'inside'
                },
                overlay : {
                    css : {
                        'background-color' : '#eee'
                    }
                }
            },
        beforeLoad: function() {
            var el, id = $(this.element).data('title-id');
            if (id) {
                el = $('#' + id);

                if (el.length) {
                    this.title = el.html();
                }
            }
        }
    });​

Working example: http://jsfiddle.net/FWTZA/372

user2559047

Here's how we did it, pulling all images and urls out of a database:

$(document).ready(function() {              
 $.fancybox(
  [ 
   { href : '/images/gallery_pic.php?id=229', title: 'Sample image one', rel : 'fancybox-thumb', class : 'fancybox-thumb'},
   { href : '/images/gallery_pic.php?id=167', title: ' Sample image two <a href="http://www.address" target="_blank">See site</a>', rel : 'fancybox-thumb', class : 'fancybox-thumb'}
  ],
  {
   type : 'image',
   autoScale : true,
   prevEffect : 'none',
   nextEffect : 'none',
   helpers : {
    title   : {
        type: 'inside',
        position: 'top'
    },

   } // closes helpers
  }               
 );
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!