简体   繁体   English

带有 html 内容的灯箱功能(引导缩略图)

[英]Lightbox functinality with html content (Bootstrap Thumbnails)

plz help me(beginner) to solve a problem.请帮助我(初学者)解决问题。 I am coding a site with bootstrap 3. I have bootstrap thumbnail on it.我正在使用引导程序 3 编写一个站点。我有引导程序缩略图。 when user will click an specific link in the thumbnail, it will show in an modal/popup.当用户单击缩略图中的特定链接时,它将显示在模式/弹出窗口中。 modals primary contents will be same with the thumbnail was clicked.模态主要内容将与单击的缩略图相同。 but there will be two button (next, previous) in the modal, by clicking them, user will view the next or previous thumbnail.但是模态中有两个按钮(下一个,上一个),通过单击它们,用户将查看下一个或上一个缩略图。 There is an large image on each thumbnail which is hidden in thumbnail view, but will show in the modal view.每个缩略图上都有一个大图像,它隐藏在缩略图视图中,但会显示在模式视图中。 by clicking next or previous buttons, the large image, n the description part will change accordingly(like carousel).通过单击下一个或上一个按钮,大图像,n 描述部分将相应更改(如轮播)。 The whole functionality is like lightbox.整个功能就像灯箱。 I have seen different jquery lightbox plugin, but either they are only with image preview, or heavy weight.我见过不同的 jquery 灯箱插件,但要么只有图像预览,要么很重。 Plz help me with the issue.请帮我解决这个问题。 I know the html/css well.我很了解 html/css。 so, i can fix any css issue, i need the jquery functionality.所以,我可以修复任何 css 问题,我需要 jquery 功能。 Please don't answer with just a lightbox plugin link, i want to use the basic jquery.请不要只用一个灯箱插件链接来回答,我想使用基本的 jquery。

Here's the thumbnails in my html:这是我的 html 中的缩略图:

<div class="container" id="lightbox">
<div class="row">
    <div class="lightbox-thumbs-wrap">
        <div class="col-xs-12 col-sm-6 col-md-3">
            <div class="thumbnail">
                <div class="tmb-outer">
                    <div class="tmb-gray">
                        <img src="img/xyz/small-icon.png">
                        <h3>Description heading</h3>
                        <p>
                            Description details here.
                        </p>
                    </div>
                    <a class="tmb-button">Click to open lightbox</a>

                    <img src="img/xyz/large-image1.png"> <!-- this image hidden in thumbnail, but will show only in modal -->
                </div>                    
            </div>
        </div> <!-- ********* end thumb *********** -->   
        <div class="col-xs-12 col-sm-6 col-md-3">
            <div class="thumbnail">
                <div class="tmb-outer">
                    <div class="tmb-gray">
                        <img src="img/xyz/small-icon2.png">
                        <h3>Description heading2</h3>
                        <p>
                            Description2 details here.
                        </p>
                    </div>
                    <a class="tmb-button">Click to open lightbox</a>

                    <img src="img/xyz/large-image2.png"> <!-- this image hidden in thumbnail, but will show only in modal -->
                </div>                    
            </div>
        </div> <!-- ********* end thumb *********** --> 
    </div>
</div>

And, the modal i want will look like:而且,我想要的模态看起来像:

<div class="modal">
<div class="overlay"></div>
<div class="modal-wrapper">
    <a href="#">click to close modal</a>
    <div class="container-fluid">
        <div class="col-sm-12 col-md-5">
            <div class="tmb-gray">
                <img src="img/xyz/small-icon.png">
                <h3>Description heading</h3>
                <p>
                    Description details here.
                </p>
            </div>
        </div>
        <div class="col-sm-12 col-md-7">
            <img src="img/xyz/large-image1.png"> <!-- large slider image, it was hidden in thumbnail -->

            <a class="next-img"><img src="img/xyz/next.png"></a>
            <a class="prev-img"><img src="img/xyz/prev.png"></a>
        </div>
    </div>
</div>

Firstly note that you should describe the problem and what has been done so far to solve it when posting a question on SO.首先请注意,在 SO 上发布问题时,您应该描述问题以及迄今为止为解决该问题所做的工作。

Secondly read Varying modal content based on trigger button at Bootstrap's docs.其次在 Bootstrap 的文档中阅读基于触发按钮的不同模式内容

And than, i think you should create one modal and change its content dynamically onload, and after pressing the previous / next images (buttons).而且,我认为您应该创建一个模式并在加载时动态更改其内容,并在按下上一个/下一个图像(按钮)之后。 I create an example that can be found at: http://jsfiddle.net/esLad6x8/我创建了一个可以在以下位置找到的示例: http : //jsfiddle.net/esLad6x8/

First create a array of object that describe your images / thumbs:首先创建一个描述图像/拇指的对象数组:

var images = new Array();
for (var i=0; i<10; i++) {
images.push({img: 'http://dummyimage.com/600x400/000/fff&text=image' + i, thumb: 'http://dummyimage.com/100x100/000/fff&text=thumb' + i, head:'heading' + i, description:'Description' + i + ' details here.'}); 
}

Alternatively you could read the above information from your thumb's grid.或者,您可以从拇指的网格中读取上述信息。

html of the modal You should use Bootstrap's modal classes to use the modal jQuery Plugin, see: http://getbootstrap.com/javascript/#modals模态的 html您应该使用 Bootstrap 的模态类来使用模态 jQuery 插件,请参阅: http : //getbootstrap.com/javascript/#modals

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
      </div>
      <div class="modal-body">
      <div class="col-sm-12 col-md-5">
            <div class="tmb-gray">
                <img src="">
                <h3>Description heading</h3>
                <p>
                    Description details here.
                </p>
            </div>
        </div>
        <div class="col-sm-12 col-md-7">
            <img src="" class="img-responsive"> <!-- large slider image, it was hidden in thumbnail -->


            <a class="prev-img btn btn-primary">Previous</a>
            <a class="next-img btn btn-primary">Next</a>
        </div>
      </div>
      <div class="modal-footer">&nbsp;</div>
    </div>
  </div>
</div>

A button to open the modal can look like that shown below:用于打开模态的按钮可能如下所示:

<button type="button" class="openmodal btn btn-primary btn-lg" data-thumb="0">
  First Thumb
</button>

The on click event of the above button:上面按钮的点击事件:

$('.openmodal').on('click',function(){
    setModalContent($( this ).data('thumb'));
    $('#myModal').modal('show');//pop up modal
});

The setModalContent function used in the preceding code can look like as follows:前面代码中使用的setModalContent函数如下所示:

function setModalContent($thumbNumber) {
$('#myModal .tmb-gray h3').text(images[$thumbNumber].head);
$('#myModal .tmb-gray h3 + p').text(images[$thumbNumber].description);
$('#myModal .tmb-gray > img').attr('src',images[$thumbNumber].thumb);
$('#myModal .modal-body img').last().attr('src',images[$thumbNumber].img);
/* set next and previous buttons */
$('.prev-img').data('thumb',($thumbNumber - 1 >= 0) ? $thumbNumber - 1 : images.length - 1);
$('.next-img').data('thumb',($thumbNumber + 1 < images.length) ? $thumbNumber + 1 : 0);
}

And finally create the click events for the previous/next navigation, which only change the content of a already opened modal:最后为上一个/下一个导航创建单击事件,这只会更改已打开的模式的内容:

$('.modal').on('click','.prev-img',function(){ setModalContent($( this ).data('thumb'));});
$('.modal').on('click','.next-img',function(){ setModalContent($( this ).data('thumb'));});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM