سؤال

I have an Image, Video, and Text

I would like to have an the Lightbox present the respective (Image, Video, and Text)
when a Image, Video, and Text is clicked.

The items have an ids #prw-item-2 The image id = #imagePreview

<a id='imagePreview' class='fancybox' href='Penguins.jpg' 
data-fancybox-group='gallery' title='Image01'><img src='Penguins.jpg' 
alt='' height='180' width='310' style='margin: 5px'/></a>

The image id = #videoPreview

<iframe id='videoPreview' height='180' width='310' 
src='http://www.youtube.com/embed/XGSy3_Czz8k'></iframe>

The image id = #textPreview

<textarea id='textPreview' class='form-control' rows='20' 
maxlength='500'>500 limit</textarea>

jQuery,
I am not sure, how to make 1 button,
switch between, item ids, and video/image/texts.

//LightBoxButtonPreview
var onClickCard = function(dst){    
var t = dst.id; //(t = item-2)
var q = '#prw-' + t; //(q = prw-item-2)
//(???) #imagePreview, #videoPreview, #textPreview

LightBox Button(???):

<a href="???" class="btn btn-default btn-primary fancybox" 
data-fancybox-group="gallery" title="ImagePreviewBtn">
<span class="glyphicon glyphicon-eye-open"></span> PreviewButton</a>

any help would be appreciated.

هل كانت مفيدة؟

المحلول

Maybe like this:

$(document).on("click", "#preview-button", function(e) {
    e.preventDefault();
    var _whatShow = $("#what-show").val();
    if (!_whatShow) return false;
    switch(_whatShow) {
        case 'image': _type ='inline'; _href='#imagePreview'; break;
        case 'video': _type ='iframe'; _href=$('#videoPreview').attr('src'); break;
        case 'text': _type ='inline'; _href='#textPreview'; break;
    }
   $.fancybox({
      href: _href,
      width: 730,
      height: 530,
      type: _type,
    }); 
});

Demo page

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top