Search code examples
javascriptjqueryhtmlsimplemodal

how to add caption and link to image gallery modal?


I am trying to customize a html template. which is

https://html5up.net/ethereal

it has a gallery with modal. i want to add a simple link and some text in that modal. but i am unable to do so.

can any one please help me.

Thank You


Solution

  • Follow these steps : each gallery image add caption and link data like this :

    <a href="images/gallery/fulls/01.jpg" class="image filtered span-3" data-position="bottom" data-url="addlink" data-caption="addcaption"><img src="images/gallery/thumbs/01.jpg" alt=""></a>
    

    in the main.js find this line

    $modalImg = $modal.find('img'),
    href = $a.attr('href');
    

    and below this add these line:

    var caption = $a.data('caption');
    var capurl = $a.data('url');
    $modal.find('.caption').remove();
    

    then find this line

    $modalImg.attr('src', href);
    

    and after this add(caption and link)

    if(caption!=undefined){
    $modalImg.before('<div class="caption"><a href="'+capurl+'">'+caption+'</a></div>');
    }