Search code examples
phpjqueryfancyboxgallerypreview

Static description and title in fancybox


I have several albums in a database. There are several images in each one. I get these albums and images by php:

    var data = [
      [
        {'href': 'http://31.media.tumblr.com/ed86baf7b4e9538aeaebc406aaa56cbc/tumblr_mmwaozmUKo1s0o4s9o1_500.jpg'},
        {'href': 'http://25.media.tumblr.com/6623ddd110dd18bffb35457cf83f771c/tumblr_mm8tcct2Av1rphpc2o1_500.jpg'},
        {'href': 'http://25.media.tumblr.com/d4fe3fcc6326cde88c14d658d521eaee/tumblr_mvbnqtsX2P1rgd6gxo1_500.jpg'}
      ],  
      [
        {'href': 'http://25.media.tumblr.com/6816c5b46d93ceebde243a9cf48f02dc/tumblr_mvn9jdNiiq1rgd6gxo1_r1_500.jpg'},
        {'href': 'http://31.media.tumblr.com/0c27cb0ba446c1f1c778452c4590eafd/tumblr_mvmwp0Cq4f1rgd6gxo1_r1_500.jpg'},
        {'href': 'http://31.media.tumblr.com/72c1f613c537f12c10e8689dc0bf093c/tumblr_mvtqoxy0N11r9asaso1_500.jpg'}
      ],  
      [
        {'href': 'http://25.media.tumblr.com/bbfb7445c08e139d945296507ad9146c/tumblr_mjdkktCfhO1qa9opio1_500.jpg'},
        {'href': 'http://31.media.tumblr.com/73924815d177266083b59d20db9c287e/tumblr_mvss8vVZew1qa9opio1_500.jpg'},
        {'href': 'http://25.media.tumblr.com/3cd96a8148b263514ffbcb32e6a0ebf8/tumblr_mvss8geomy1qa9opio1_500.jpg'}
      ]  
    ]; 

Then I use fancybox:

 $(document).ready(function() {


                $('#gallery').on('click', 'img', function() {
                    var index = $(this).parent().index();

                $.fancybox(data[index], {
                title: {
                        type: 'inside'
                    },
                title:  $(this).attr('rel'), 
                afterLoad: function () {
                        this.title = this.title + ' ' + $(this.element).find('img').attr('alt');
                    }
                });

                return false;
                });
            });

The code of previews looks like and generate by php:

<ul id="gallery">
  <li><img src="preview1.jpg"></li>
  <li><img src="preview2.jpg"></li>
  <li><img src="preview3.jpg"></li>
   ....
</ul>

I want to see a static description of the whole album anywhere (under, bottom, on the right, on the left) when I watching gallery. I mean when I slide my images in someone of albums I see description of this album. In modal window also. Is it real by fancybox? And I want to see static title also.

Can anyone help me? If you don't understand you can ask me questions for more detail answer.

Thanks.


Solution

  • The simplest way is to add album description to image title after some divider, for example a couple of <br>'s. You can take the album description from an attribute of the <img>.

    Here is an example for you: http://jsfiddle.net/n21vma5m/1/