0

I would use the title attribute as a caption in a gallery. The caption will be in a fixed position on the page. I can't update dynamically the content of the title attribute in the div showing various caption one at a time.

html markup

<!-- fist slide -->  
<div class="section" id="gallery-start">
    <div class="content">
        <img src="img/1.jpg" title="Caption text 1">
    </div>
</div>

...

<!-- caption -->     
<div class="caption-display"></div>

js script

$('.caption-display').each(function(i) {
    $(this).html($('.gallery-element').eq(i).attr('title'));
});

example

Jsfiddle

Sathish
  • 2,440
  • 1
  • 11
  • 27

1 Answers1

0

I hope it will be useful, I solved in this way.

html

<!-- caption -->
<div class="caption-box">
    <p class="caption-description">
        Caption text 1
    </p>
</div>

css

.caption-description
{
    display: none;
}

.caption-display
{ 
    position: fixed;
    bottom: 10px;
    left: 10px;
}

js

$(window).load(function () {
    var window_center = $(window).height();
    var threshold = 0;
    $(window).on("scroll resize", function () {
        scroll = $(window).scrollTop();

        $('.section').each(function () {
            var post_center = $(this).height()/2 + $(this).offset().top;
            if (post_center + threshold < window_center + scroll ||
                post_center - threshold < window_center + scroll){
                if (!$(this).hasClass('active')){
                    $('.section').removeClass('active');
                    $(this).addClass('active');
                    $('.caption-display').hide();
                    var newDescr = $(this).find('.caption-description');
                    $('.caption-display').html(newDescr.html());    
                    $('.caption-display').fadeIn('slow');
                }
            }
        });
    });

    $(document).ready(function () {
        $(window).trigger('scroll'); // init the value
    });
});