Add Photoswipe to table gallery - gallery

I want to add Photoswipe to a gallery that ive made inside a table. Here is a sample site.
<
I want to keep the layout of the gallery but when you click each image it pulls up the Photoswipe viewer, can I do this?
Jfiddle: https://jsfiddle.net/baL04a9o/

This is photoswipe gallery with table. Code
First gallery:
<div class="my-gallery" itemscope itemtype="http://schema.org/ImageGallery">
<table>
<tr>
<td>
<figure >
<a href="https://farm3.staticflickr.com/2567/5697107145_a4c2eaa0cd_o.jpg" itemprop="contentUrl" data-size="1024x1024">
<img src="https://farm3.staticflickr.com/2567/5697107145_3c27ff3cd1_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 1</figcaption>
</figure>
</td>
<td>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm2.staticflickr.com/1043/5186867718_06b2e9e551_b.jpg" itemprop="contentUrl" data-size="964x1024">
<img src="https://farm2.staticflickr.com/1043/5186867718_06b2e9e551_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 2</figcaption>
</figure>
</td>
</tr>
<tr>
<td>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm7.staticflickr.com/6175/6176698785_7dee72237e_b.jpg" itemprop="contentUrl" data-size="1024x683">
<img src="https://farm7.staticflickr.com/6175/6176698785_7dee72237e_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 3</figcaption>
</figure>
</td>
<td>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm6.staticflickr.com/5023/5578283926_822e5e5791_b.jpg" itemprop="contentUrl" data-size="1024x768">
<img src="https://farm6.staticflickr.com/5023/5578283926_822e5e5791_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 4</figcaption>
</figure>
</td>
</tr>
</table>
</div>
<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
<!-- Background of PhotoSwipe.
It's a separate element, as animating opacity is faster than rgba(). -->
<div class="pswp__bg"></div>
<!-- Slides wrapper with overflow:hidden. -->
<div class="pswp__scroll-wrap">
<!-- Container that holds slides. PhotoSwipe keeps only 3 slides in DOM to save memory. -->
<!-- don't modify these 3 pswp__item elements, data is added later on. -->
<div class="pswp__container">
<div class="pswp__item"></div>
<div class="pswp__item"></div>
<div class="pswp__item"></div>
</div>
<!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
<div class="pswp__ui pswp__ui--hidden">
<div class="pswp__top-bar">
<!-- Controls are self-explanatory. Order can be changed. -->
<div class="pswp__counter"></div>
<button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
<button class="pswp__button pswp__button--share" title="Share"></button>
<button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>
<button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>
<!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
<!-- element will get class pswp__preloader--active when preloader is running -->
<div class="pswp__preloader">
<div class="pswp__preloader__icn">
<div class="pswp__preloader__cut">
<div class="pswp__preloader__donut"></div>
</div>
</div>
</div>
</div>
<div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
<div class="pswp__share-tooltip"></div>
</div>
<button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
</button>
<button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
</button>
<div class="pswp__caption">
<div class="pswp__caption__center"></div>
</div>
</div>
</div>
</div>

Related

Spread out Bootstrap images with captions within a column

I have a pricing comparison section of a Bootstrap 5 website, one column displays the images perfectly (without captions), however whenever I add a paragraph tag for the caption, the images stack on top of one another instead of staying inline in a row.
Here is the code for images without captions:
<div class="col-lg-4 col-md-6" data-aos="zoom-in" data-aos-delay="150">
<div class="box">
<h3>Basic</h3>
<h4><sup>£</sup>4.50<span> / month</span></h4>
<ul>
<li><i class="bi bi-check-circle"></i>Web and mobile versions of Office apps only</li>
<li><i class="bi bi-check-circle"></i>Chat, call, meet up to 300 attendees</li>
<li><i class="bi bi-check-circle"></i>1 TB of cloud storage per user</li>
<li><i class="bi bi-check-circle"></i>Business-class email</li>
<li><i class="bi bi-check-circle"></i>Standard security</li>
<li><i class="bi bi-check-circle"></i>Anytime phone and web support</li>
</ul>
<p>Web and mobile apps and services:</p>
<img src="assets/img/Word_64x64.png" alt="" class="img-fluid">
<img src="assets/img/Excel_64x64.png" alt="" class="img-fluid">
<img src="assets/img/Outlook_64x64.png" alt="" class="img-fluid">
<img src="assets/img/PowerPoint_64x64.png" alt="" class="img-fluid">
<img src="assets/img/Microsoft_Teams_64x64.png" alt="" class="img-fluid">
<img src="assets/img/Outlook_64x64.png" alt="" class="img-fluid">
<img src="assets/img/Exchange_64x64.png" alt="" class="img-fluid">
<img src="assets/img/OneDrive_64x64.png" alt="" class="img-fluid">
<img src="assets/img/SharePoint_64x64.png" alt="" class="img-fluid">
<div class="btn-wrap">
Buy Now
</div>
</div>
</div>
Here is the code for images with captions:
<div class="col-lg-4 col-md-6 mt-4 mt-lg-0" data-aos="zoom-in" data-aos-delay="150">
<div class="box featured">
<h3>Premium</h3>
<h4><sup>£</sup>16.60<span> / month</span></h4>
<b><p>Everything in Business Standard, plus:</p></b>
<ul>
<li><i class="bi bi-check-circle white"></i>Advanced security
<li><i class="bi bi-check-circle white"></i>Access and data control
<li><i class="bi bi-check-circle white"></i>Cyberthreat protection</li>
<li><i class="bi bi-check-circle white"></i>Mobile device management</li>
</ul>
<p>Desktop, web, and mobile apps and services:</p>
<img src="assets/img/Excel_64x64.png" alt="" class="img-fluid"><p>Excel</p>
<img src="assets/img/Outlook_64x64.png" alt="" class="img-fluid"><p>Outlook</p>
<img src="assets/img/PowerPoint_64x64.png" alt="" class="img-fluid"><p>PowerPoint</p>
<img src="assets/img/Microsoft_Teams_64x64.png" alt="" class="img-fluid"><p>Teams</p>
<img src="assets/img/Outlook_64x64.png" alt="" class="img-fluid"><p>Outlook</p>
<img src="assets/img/Exchange_64x64.png" alt="" class="img-fluid"><p>Exchange</p>
<img src="assets/img/OneDrive_64x64.png" alt="" class="img-fluid"><p>OneDrive</p>
<img src="assets/img/SharePoint_64x64.png" alt="" class="img-fluid"><p>SharePoint</p>
<img src="assets/img/Access_64x64.png" alt="" class="img-fluid"><p>Access</p>
<img src="assets/img/Publisher_64x64.png" alt="" class="img-fluid"><p>Publisher</p>
<div class="btn-wrap">
Buy Now
</div>
</div>
</div>
What do I need to change to keep the icons inline?
Try wrapping your <img> and the <p> inside a <div>. Since <p> is a block-level element, meaning that any element after <p> will automatically be added to a new line.
Here's my example
<div>
<img/>
<span>your text here</span>
</div>
Also note that I'm changing <p> with <span>
Update code
To centre all the content
<div class="d-flex flex-wrap align-items-center justify-content-center">
...
</div>
Try to use the flex property of bootstrap
<div class="d-flex flex-column align-items-center justify-content-center">
<img/>
<p>your text here</p>
</div>
for more details check out the bootstrap doc[https://getbootstrap.com/docs/5.0/utilities/flex/]
and You can wrap all the image div with flex-wrap
<div class="d-flex flex-wrap">
...
</div>

Horizontal scrollbar not working when browser width is re-sized?

I have a div and within that i have divs with images in. what i want is for all the images to display but when the browser width is re-sized(smaller) for an automatic horizontal scrollbar to appear rather than the images stacking up below. I'm trying to create this but its not working. Any help??
<div style="height:80px;width:auto;border:1px solid red;white-space:nowrap;overflow-y:hidden;-ms-overflow-y:hidden;overflow-x:scroll;-ms-overflow-x:scroll;">
<div style="height:60px;width:90px;display:inline-block;">
<a href="#" >
<img style="max-height:60px;height:auto;max-width:90px;width:auto;margin:0 auto;padding:5px;display:inline-block;vertical-align:middle;" src="img1.png" />
</a>
</div>
<div style="height:60px;width:90px;display:inline-block;">
<a href="#" >
<img style="max-height:60px;height:auto;max-width:90px;width:auto;margin:0 auto;padding:5px;display:inline-block;vertical-align:middle;" src="img1.png" />
</a>
</div>
<div style="height:60px;width:90px;display:inline-block;">
<a href="#" >
<img style="max-height:60px;height:auto;max-width:90px;width:auto;margin:0 auto;padding:5px;display:inline-block;vertical-align:middle;" src="img1.png" />
</a>
</div>
<div style="height:60px;width:90px;display:inline-block;">
<a href="#" >
<img style="max-height:60px;height:auto;max-width:90px;width:auto;margin:0 auto;padding:5px;display:inline-block;vertical-align:middle;" src="img1.png" />
</a>
</div>
<div style="height:60px;width:90px;display:inline-block;">
<a href="#" >
<img style="max-height:60px;height:auto;max-width:90px;width:auto;margin:0 auto;padding:5px;display:inline-block;vertical-align:middle;" src="img1.png" />
</a>
</div>
</div>
Your code seems to work for me as expected. https://fiddle.jshell.net/ph110293/goetup62/
It didn't work on Firefox ONLY. For Firefox I had to set the 'fieldset' tag style to be 'display:table-column;'. As my main div was inside tags which was in another div with a class of 'container' (Bootstrap), the fieldset kept taking the container width.

Binding Repeater data to Dynamic tab in asp.net

I wanted to bind the repeater's data to Dynamic tab of year the image for which i am attaching
enter image description here
the repeater code is as below:
<!--begin isotope -->
<div class="isotope col-lg-12">
<!--begin portfolio filter -->
<ul id="filter" class="option-set clearfix">
<li data-filter="*" class="selected"><a>All</a></li>
<asp:Repeater ID="rpYear" runat="server" OnItemDataBound="rpYear_ItemDataBound">
<ItemTemplate>
<li data-filter='<%#Eval("Year") %>'>
<a>
<asp:Label ID="lbl" runat="server" Text='<%#Eval("Year") %>'></asp:Label>
</a>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
<ul id="list" class="portfolio_list clearfix">
<asp:Repeater ID="rpImagedetails" runat="server">
<ItemTemplate>
<li class="list_item col-lg-4 col-md-4 col-sm-4 <%#Eval("Year") %> ">
<div class="recent-item">
<figure>
<div class="touching medium">
<img src='<%# "FileUpload/Eventpic/"+ Eval("Image") %>' alt="" />
<div class="hovers">
<i class="fa fa-search"></i>
<!--<i class="fa fa-link"></i>-->
</div>
</div>
<figcaption class="item-description">
<h5><%#Eval("Title") %></h5>
<span><%#Eval("Date") %>
<br>
<%#Eval("Stallno") %>
<br>
<%#Eval("Location") %></span>
</figcaption>
</figure>
</div>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
</div>
</div>
<!--./span12-->
</div>
the code behind file is as below:
protected void Page_Load(object sender, EventArgs e)
{
GetYear();
BindEventVideo1();
}
public void GetYear()
{
DataSet ds = EventVideo.GetYear();
if (ds.Tables[0].Rows.Count > 0)
{
rpYear.DataSource = ds;
rpYear.DataBind();
}
}
protected void rpYear_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
Repeater rpImages = (Repeater)e.Item.FindControl("rpImagedetails");
Label item = (Label)e.Item.FindControl("lbl");
string Year = item.Text;
ViewState["Year"] = Year;
}
}
public void BindEventVideo1()
{
DataSet ds = EventVideo.GetyearImages(ViewState["Year"].ToString());
if (ds.Tables[0].Rows.Count > 0)
{
rpImagedetails.DataSource = ds.Tables[0];
rpImagedetails.DataBind();
}
}
I am new to asp.net so kindly help.
Thanks in advance.
the Html code is
<div class="isotope col-lg-12">
<!--begin portfolio filter -->
<ul id="filter" class="option-set clearfix">
<li data-filter="*" class="selected">All</li>
<li data-filter=".2014">2014</li>
<li data-filter=".2012">2012</li>
<!-- <li data-filter=".2011">2011</li>-->
<li data-filter=".2010">2010</li>
</ul>
<!--end portfolio filter -->
<!--begin portfolio_list -->
<ul id="list" class="portfolio_list clearfix">
<!-- Begin Portfolio item -->
<li class="list_item col-lg-4 col-md-4 col-sm-4 2014">
<div class="recent-item">
<figure>
<div class="touching medium">
<img src="images/events/2014-1.jpg" alt="" />
<div class="hovers">
<i class="fa fa-search"></i>
<!--<i class="fa fa-link"></i>-->
</div>
</div>
<figcaption class="item-description">
<h5>Elecrama 2014</h5>
<span>Date : 8th - 12th Jan '2014. <br>
Stall No: H2A55
<br>
BIEC,
Bangalore, India</span>
</figcaption>
</figure>
</div>
</li>
<!-- End Portfolio item -->
<!-- Begin Portfolio item -->
<li class="list_item col-lg-4 col-md-4 col-sm-4 2014">
<div class="recent-item">
<figure>
<div class="touching medium">
<img src="images/events/2014-2.jpg" alt="" />
<div class="hovers">
<i class="fa fa-search"></i>
<!--<i class="fa fa-link"></i>-->
</div>
</div>
<figcaption class="item-description">
<h5>Elecrama 2014</h5>
<span>Date : 8th - 12th Jan '2014. <br>
Stall No: H2A55
<br>
BIEC,
Bangalore, India</span>
</figcaption>
</figure>
</div>
</li>
<!-- End Portfolio item -->
<!-- Begin Portfolio item -->
<!--<li class="list_item col-lg-4 col-md-4 col-sm-4 2012">
<div class="recent-item">
<figure>
<div class="touching medium">
<img src="img/portfolio/portfolio_2.png" alt="" />
<div class="hovers">
</i>
<i class="fa fa-link"></i>
</div>
</div>
<figcaption class="item-description">
<h5>Power & Electricity World Africa 2012</h5>
<span>Date : 27th - 28th March '2012<br>
Stall No: ZNB-9 IND 10,
Sandton Convention Centre,
Johannesburg, South Africa</span>
</figcaption>
</figure>
</div>
</li>-->
<!-- End Portfolio item -->
<!-- Begin Portfolio item -->
<li class="list_item col-lg-4 col-md-4 col-sm-4 2012">
<div class="recent-item">
<figure>
<div class="touching medium">
<img src="images/events/2012-1.jpg" alt="" />
<div class="hovers">
<i class="fa fa-search"></i>
<!--<i class="fa fa-link"></i>-->
</div>
</div>
<figcaption class="item-description">
<h5>Elecrama 2012</h5>
<span>Date : 18th - 22nd Jan'2012<br>
Stall No: H5 E10R70<br>
Bombay Exhibition Centre,
Mumbai, INDIA</span>
</figcaption>
</figure>
</div>
</li>
<!-- End Portfolio item -->
<!-- Begin Portfolio item -->
<li class="list_item col-lg-4 col-md-4 col-sm-4 2012">
<div class="recent-item">
<figure>
<div class="touching medium">
<img src="images/events/2012-2.jpg" alt="" />
<div class="hovers">
<i class="fa fa-search"></i>
<!--<i class="fa fa-link"></i>-->
</div>
</div>
<figcaption class="item-description">
<h5>Elecrama 2012</h5>
<span>Date : 18th - 22nd Jan'2012<br>
Stall No: H5 E10R70<br>
Bombay Exhibition Centre,
Mumbai, INDIA</span>
</figcaption>
</figure>
</div>
</li>
<!-- End Portfolio item -->
<!-- Begin Portfolio item -->
<li class="list_item col-lg-4 col-md-4 col-sm-4 2012">
<div class="recent-item">
<figure>
<div class="touching medium">
<img src="images/events/2012-3.jpg" alt="" />
<div class="hovers">
<i class="fa fa-search"></i>
<!--<i class="fa fa-link"></i>-->
</div>
</div>
<figcaption class="item-description">
<h5>Elecrama 2012</h5>
<span>Date : 18th - 22nd Jan'2012<br>
Stall No: H5 E10R70<br>
Bombay Exhibition Centre,
Mumbai, INDIA</span>
</figcaption>
</figure>
</div>
</li>
<!-- End Portfolio item -->
<!-- Begin Portfolio item -->
<!--<li class="list_item col-lg-4 col-md-4 col-sm-4 2012">
<div class="recent-item">
<figure>
<div class="touching medium">
<img src="img/portfolio/portfolio_4.png" alt="" />
<div class="hovers">
</i>
<i class="fa fa-link"></i>
</div>
</div>
<figcaption class="item-description">
<h5>Middle East Electricity 2012</h5>
<span>Date : 7th - 9th Feb'2012<br>
Stall No: ZN 18
India Pavalion <br>
International Exhibition Centre,
Dubai, UAE</span>
</figcaption>
</figure>
</div>
</li>-->
<!-- End Portfolio item -->
<!-- Begin Portfolio item -->
<!--<li class="list_item col-lg-4 col-md-4 col-sm-4 2011">
<div class="recent-item">
<figure>
<div class="touching medium">
<img src="img/portfolio/portfolio_5.png" alt="" />
<div class="hovers">
</i>
<i class="fa fa-link"></i>
</div>
</div>
<figcaption class="item-description">
<h5>Middle East Electricity 2011</h5>
<span>Date : 8th - 10th Feb'2011<br>
Stall No: ZQ 58,
India Pavalion <br>
International Exhibition Centre,
Dubai, UAE</span>
</figcaption>
</figure>
</div>
</li>-->
<!-- End Portfolio item -->
<!-- Begin Portfolio item -->
<li class="list_item col-lg-4 col-md-4 col-sm-4 2010">
<div class="recent-item">
<figure>
<div class="touching medium">
<img src="images/events/2010-1.jpg" alt="" />
<div class="hovers">
<i class="fa fa-search"></i>
<!--<i class="fa fa-link"></i>-->
</div>
</div>
<figcaption class="item-description">
<h5>Elecrama 2010</h5>
<span>Date : 20th - 24th Jan'2010<br>
Stall No: H1 G50<br>
Bombay Exhibition Centre,
Mumbai, INDIA</span>
</figcaption>
</figure>
</div>
</li>
<!-- End Portfolio item -->
<!-- Begin Portfolio item -->
<li class="list_item col-lg-4 col-md-4 col-sm-4 2010">
<div class="recent-item">
<figure>
<div class="touching medium">
<img src="images/events/2010-2.jpg" alt="" />
<div class="hovers">
<i class="fa fa-search"></i>
<!-- <i class="fa fa-link"></i>-->
</div>
</div>
<figcaption class="item-description">
<h5>Elecrama 2010</h5>
<span>Date : 20th - 24th Jan'2010<br>
Stall No: H1 G50<br>
Bombay Exhibition Centre,
Mumbai, INDIA</span>
</figcaption>
</figure>
</div>
</li>
<!-- End Portfolio item -->
<!-- Begin Portfolio item -->
<li class="list_item col-lg-4 col-md-4 col-sm-4 2010">
<div class="recent-item">
<figure>
<div class="touching medium">
<img src="images/events/2010-3.jpg" alt="" />
<div class="hovers">
<i class="fa fa-search"></i>
<!-- <i class="fa fa-link"></i>-->
</div>
</div>
<figcaption class="item-description">
<h5>Elecrama 2010</h5>
<span>Date : 20th - 24th Jan'2010<br>
Stall No: H1 G50<br>
Bombay Exhibition Centre,
Mumbai, INDIA</span>
</figcaption>
</figure>
</div>
</li>
<!-- End Portfolio item -->
<!-- Begin Portfolio item -->
<!--<li class="list_item col-lg-4 col-md-4 col-sm-4 responsive">
<div class="recent-item">
<figure>
<div class="touching medium">
<img src="img/portfolio/portfolio_7.png" alt="" />
<div class="hovers">
</i>
<i class="fa fa-link"></i>
</div>
</div>
<figcaption class="item-description">
<h5>consectetur adipisicing</h5>
<span>Technology</span>
</figcaption>
</figure>
</div>
</li>-->
<!-- End Portfolio item -->
<!-- Begin Portfolio item -->
<!--<li class="list_item col-lg-4 col-md-4 col-sm-4 branding">
<div class="recent-item">
<figure>
<div class="touching medium">
<img src="img/portfolio/portfolio_8.png" alt="" />
<div class="hovers">
</i>
<i class="fa fa-link"></i>
</div>
</div>
<figcaption class="item-description">
<h5>ipsum dolor</h5>
<span>Technology</span>
</figcaption>
</figure>
</div>
</li>-->
<!-- End Portfolio item -->
<!-- Begin Portfolio item -->
<!--<li class="list_item col-lg-4 col-md-4 col-sm-4 branding">
<div class="recent-item">
<figure>
<div class="touching medium">
<img src="img/portfolio/portfolio_9.png" alt="" />
<div class="hovers">
</i>
<i class="fa fa-link"></i>
</div>
</div>
<figcaption class="item-description">
<h5>lorem ipsum</h5>
<span>Technology</span>
</figcaption>
</figure>
</div>
</li>-->
<!-- End Portfolio item -->
</ul> <!--end portfolio_list -->
</div>
Adding the Image from view code
enter image description here
I think you need 2 repeater if you are using ASP.NET(aspx and ascx)
1) for displaying year as a tab
2) another repeater for displaying images with details
Step-to-follow
1) Have this all data in dataset set in session
2) get distinct year and add default tab as 'All' and bind this year data to Repeater as horizontal, each repeater cell contains the link button and on click you have to redirect to server and get the filtered records from the session dataset and show it on 2nd repeater
2)on each 1st repeater-link button click event- get the year and filter out the records from session database and create in-memory dataset and fill it and bind it to 2nd dataset
I finally figured out the reason for it.
<ul id="filter" class="option-set clearfix">
<li data-filter="*" class="selected"><a>All</a></li>
<asp:Repeater ID="rpYear" runat="server">
<ItemTemplate>
<li data-filter=".<%#Eval("Year") %>"><%#Eval("Year") %></li>
</ItemTemplate>
</asp:Repeater>
</ul>
In earlier Question i was missing anchor tag section ,so it was not able to target to repeater and also In this <%#Eval("Year") %> i missed out DOT(.) representing the class.

PhotoSwipe.com gallery picture alignment

I'm trying to get PhotoSwipe gallery to line-up my pictures
Link to the code: http://codepen.io/anon/pen/vOvZeL
Is there any other way than adding a absolute height attribute to the figure-tag?
Or any way that the "row height" is variable (as high as the highest imange)?
Right now it looks like that:
http://s27.postimg.org/x4eyro4gj/Capture.png
And here is what I'm expecting:
http://s10.postimg.org/d03qh5tyx/Untitled.png
html
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm3.staticflickr.com/2567/5697107145_a4c2eaa0cd_o.jpg" itemprop="contentUrl" data-size="1024x1024">
<img src="https://farm3.staticflickr.com/2567/5697107145_3c27ff3cd1_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 1</figcaption>
</figure>
<figure>...
</div>
css:
.my-gallery {
width: 100%;
float: left;
}
.my-gallery img {
width: 100%;
height: auto;
}
.my-gallery figure {
height: 200px;
display: block;
float: left;
margin: 0 5px 5px 0;
width: 150px;
}
.my-gallery figcaption {
display: none;
}
You have to set fix height to .my-gallery figure class.
var initPhotoSwipeFromDOM = function(gallerySelector) {
// parse slide data (url, title, size ...) from DOM elements
// (children of gallerySelector)
var parseThumbnailElements = function(el) {
var thumbElements = el.childNodes,
numNodes = thumbElements.length,
items = [],
figureEl,
linkEl,
size,
item;
for (var i = 0; i < numNodes; i++) {
figureEl = thumbElements[i]; // <figure> element
// include only element nodes
if (figureEl.nodeType !== 1) {
continue;
}
linkEl = figureEl.children[0]; // <a> element
size = linkEl.getAttribute('data-size').split('x');
// create slide object
item = {
src: linkEl.getAttribute('href'),
w: parseInt(size[0], 10),
h: parseInt(size[1], 10)
};
if (figureEl.children.length > 1) {
// <figcaption> content
item.title = figureEl.children[1].innerHTML;
}
if (linkEl.children.length > 0) {
// <img> thumbnail element, retrieving thumbnail url
item.msrc = linkEl.children[0].getAttribute('src');
}
item.el = figureEl; // save link to element for getThumbBoundsFn
items.push(item);
}
return items;
};
// find nearest parent element
var closest = function closest(el, fn) {
return el && (fn(el) ? el : closest(el.parentNode, fn));
};
// triggers when user clicks on thumbnail
var onThumbnailsClick = function(e) {
e = e || window.event;
e.preventDefault ? e.preventDefault() : e.returnValue = false;
var eTarget = e.target || e.srcElement;
// find root element of slide
var clickedListItem = closest(eTarget, function(el) {
return (el.tagName && el.tagName.toUpperCase() === 'FIGURE');
});
if (!clickedListItem) {
return;
}
// find index of clicked item by looping through all child nodes
// alternatively, you may define index via data- attribute
var clickedGallery = clickedListItem.parentNode,
childNodes = clickedListItem.parentNode.childNodes,
numChildNodes = childNodes.length,
nodeIndex = 0,
index;
for (var i = 0; i < numChildNodes; i++) {
if (childNodes[i].nodeType !== 1) {
continue;
}
if (childNodes[i] === clickedListItem) {
index = nodeIndex;
break;
}
nodeIndex++;
}
if (index >= 0) {
// open PhotoSwipe if valid index found
openPhotoSwipe(index, clickedGallery);
}
return false;
};
// parse picture index and gallery index from URL (#&pid=1&gid=2)
var photoswipeParseHash = function() {
var hash = window.location.hash.substring(1),
params = {};
if (hash.length < 5) {
return params;
}
var vars = hash.split('&');
for (var i = 0; i < vars.length; i++) {
if (!vars[i]) {
continue;
}
var pair = vars[i].split('=');
if (pair.length < 2) {
continue;
}
params[pair[0]] = pair[1];
}
if (params.gid) {
params.gid = parseInt(params.gid, 10);
}
return params;
};
var openPhotoSwipe = function(index, galleryElement, disableAnimation, fromURL) {
var pswpElement = document.querySelectorAll('.pswp')[0],
gallery,
options,
items;
items = parseThumbnailElements(galleryElement);
// define options (if needed)
options = {
// define gallery index (for URL)
galleryUID: galleryElement.getAttribute('data-pswp-uid'),
getThumbBoundsFn: function(index) {
// See Options -> getThumbBoundsFn section of documentation for more info
var thumbnail = items[index].el.getElementsByTagName('img')[0], // find thumbnail
pageYScroll = window.pageYOffset || document.documentElement.scrollTop,
rect = thumbnail.getBoundingClientRect();
return {
x: rect.left,
y: rect.top + pageYScroll,
w: rect.width
};
}
};
// PhotoSwipe opened from URL
if (fromURL) {
if (options.galleryPIDs) {
// parse real index when custom PIDs are used
// http://photoswipe.com/documentation/faq.html#custom-pid-in-url
for (var j = 0; j < items.length; j++) {
if (items[j].pid == index) {
options.index = j;
break;
}
}
} else {
// in URL indexes start from 1
options.index = parseInt(index, 10) - 1;
}
} else {
options.index = parseInt(index, 10);
}
// exit if index not found
if (isNaN(options.index)) {
return;
}
if (disableAnimation) {
options.showAnimationDuration = 0;
}
// Pass data to PhotoSwipe and initialize it
gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options);
gallery.init();
};
// loop through all gallery elements and bind events
var galleryElements = document.querySelectorAll(gallerySelector);
for (var i = 0, l = galleryElements.length; i < l; i++) {
galleryElements[i].setAttribute('data-pswp-uid', i + 1);
galleryElements[i].onclick = onThumbnailsClick;
}
// Parse URL and open gallery if it contains #&pid=3&gid=1
var hashData = photoswipeParseHash();
if (hashData.pid && hashData.gid) {
openPhotoSwipe(hashData.pid, galleryElements[hashData.gid - 1], true, true);
}
};
// execute above function
initPhotoSwipeFromDOM('.my-gallery');
.my-gallery {
width: 100%;
float: left;
}
.my-gallery img {
width: 100%;
height: auto;
}
.my-gallery figure {
display: block;
float: left;
margin: 0 5px 5px 0;
width: 150px;
height: 150px;
}
.my-gallery figcaption {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="my-gallery" itemscope itemtype="http://schema.org/ImageGallery">
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm3.staticflickr.com/2567/5697107145_a4c2eaa0cd_o.jpg" itemprop="contentUrl" data-size="1024x1024">
<img src="https://farm3.staticflickr.com/2567/5697107145_3c27ff3cd1_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 1</figcaption>
</figure>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm2.staticflickr.com/1043/5186867718_06b2e9e551_b.jpg" itemprop="contentUrl" data-size="964x1024">
<img src="https://farm2.staticflickr.com/1043/5186867718_06b2e9e551_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 2</figcaption>
</figure>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm7.staticflickr.com/6175/6176698785_7dee72237e_b.jpg" itemprop="contentUrl" data-size="1024x683">
<img src="https://farm7.staticflickr.com/6175/6176698785_7dee72237e_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 3</figcaption>
</figure>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm6.staticflickr.com/5023/5578283926_822e5e5791_b.jpg" itemprop="contentUrl" data-size="1024x768">
<img src="https://farm6.staticflickr.com/5023/5578283926_822e5e5791_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 4</figcaption>
</figure>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm3.staticflickr.com/2567/5697107145_a4c2eaa0cd_o.jpg" itemprop="contentUrl" data-size="1024x1024">
<img src="https://farm3.staticflickr.com/2567/5697107145_3c27ff3cd1_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 1</figcaption>
</figure>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm2.staticflickr.com/1043/5186867718_06b2e9e551_b.jpg" itemprop="contentUrl" data-size="964x1024">
<img src="https://farm2.staticflickr.com/1043/5186867718_06b2e9e551_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 2</figcaption>
</figure>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm7.staticflickr.com/6175/6176698785_7dee72237e_b.jpg" itemprop="contentUrl" data-size="1024x683">
<img src="https://farm7.staticflickr.com/6175/6176698785_7dee72237e_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 3</figcaption>
</figure>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm6.staticflickr.com/5023/5578283926_822e5e5791_b.jpg" itemprop="contentUrl" data-size="1024x768">
<img src="https://farm6.staticflickr.com/5023/5578283926_822e5e5791_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 4</figcaption>
</figure>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm3.staticflickr.com/2567/5697107145_a4c2eaa0cd_o.jpg" itemprop="contentUrl" data-size="1024x1024">
<img src="https://farm3.staticflickr.com/2567/5697107145_3c27ff3cd1_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 1</figcaption>
</figure>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm2.staticflickr.com/1043/5186867718_06b2e9e551_b.jpg" itemprop="contentUrl" data-size="964x1024">
<img src="https://farm2.staticflickr.com/1043/5186867718_06b2e9e551_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 2</figcaption>
</figure>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm7.staticflickr.com/6175/6176698785_7dee72237e_b.jpg" itemprop="contentUrl" data-size="1024x683">
<img src="https://farm7.staticflickr.com/6175/6176698785_7dee72237e_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 3</figcaption>
</figure>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm6.staticflickr.com/5023/5578283926_822e5e5791_b.jpg" itemprop="contentUrl" data-size="1024x768">
<img src="https://farm6.staticflickr.com/5023/5578283926_822e5e5791_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 4</figcaption>
</figure>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm3.staticflickr.com/2567/5697107145_a4c2eaa0cd_o.jpg" itemprop="contentUrl" data-size="1024x1024">
<img src="https://farm3.staticflickr.com/2567/5697107145_3c27ff3cd1_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 1</figcaption>
</figure>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm2.staticflickr.com/1043/5186867718_06b2e9e551_b.jpg" itemprop="contentUrl" data-size="964x1024">
<img src="https://farm2.staticflickr.com/1043/5186867718_06b2e9e551_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 2</figcaption>
</figure>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm7.staticflickr.com/6175/6176698785_7dee72237e_b.jpg" itemprop="contentUrl" data-size="1024x683">
<img src="https://farm7.staticflickr.com/6175/6176698785_7dee72237e_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 3</figcaption>
</figure>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm6.staticflickr.com/5023/5578283926_822e5e5791_b.jpg" itemprop="contentUrl" data-size="1024x768">
<img src="https://farm6.staticflickr.com/5023/5578283926_822e5e5791_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 4</figcaption>
</figure>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm3.staticflickr.com/2567/5697107145_a4c2eaa0cd_o.jpg" itemprop="contentUrl" data-size="1024x1024">
<img src="https://farm3.staticflickr.com/2567/5697107145_3c27ff3cd1_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 1</figcaption>
</figure>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm2.staticflickr.com/1043/5186867718_06b2e9e551_b.jpg" itemprop="contentUrl" data-size="964x1024">
<img src="https://farm2.staticflickr.com/1043/5186867718_06b2e9e551_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 2</figcaption>
</figure>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm7.staticflickr.com/6175/6176698785_7dee72237e_b.jpg" itemprop="contentUrl" data-size="1024x683">
<img src="https://farm7.staticflickr.com/6175/6176698785_7dee72237e_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 3</figcaption>
</figure>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm6.staticflickr.com/5023/5578283926_822e5e5791_b.jpg" itemprop="contentUrl" data-size="1024x768">
<img src="https://farm6.staticflickr.com/5023/5578283926_822e5e5791_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 4</figcaption>
</figure>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm3.staticflickr.com/2567/5697107145_a4c2eaa0cd_o.jpg" itemprop="contentUrl" data-size="1024x1024">
<img src="https://farm3.staticflickr.com/2567/5697107145_3c27ff3cd1_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 1</figcaption>
</figure>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm2.staticflickr.com/1043/5186867718_06b2e9e551_b.jpg" itemprop="contentUrl" data-size="964x1024">
<img src="https://farm2.staticflickr.com/1043/5186867718_06b2e9e551_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 2</figcaption>
</figure>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm7.staticflickr.com/6175/6176698785_7dee72237e_b.jpg" itemprop="contentUrl" data-size="1024x683">
<img src="https://farm7.staticflickr.com/6175/6176698785_7dee72237e_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 3</figcaption>
</figure>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm6.staticflickr.com/5023/5578283926_822e5e5791_b.jpg" itemprop="contentUrl" data-size="1024x768">
<img src="https://farm6.staticflickr.com/5023/5578283926_822e5e5791_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 4</figcaption>
</figure>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm3.staticflickr.com/2567/5697107145_a4c2eaa0cd_o.jpg" itemprop="contentUrl" data-size="1024x1024">
<img src="https://farm3.staticflickr.com/2567/5697107145_3c27ff3cd1_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 1</figcaption>
</figure>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm2.staticflickr.com/1043/5186867718_06b2e9e551_b.jpg" itemprop="contentUrl" data-size="964x1024">
<img src="https://farm2.staticflickr.com/1043/5186867718_06b2e9e551_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 2</figcaption>
</figure>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm7.staticflickr.com/6175/6176698785_7dee72237e_b.jpg" itemprop="contentUrl" data-size="1024x683">
<img src="https://farm7.staticflickr.com/6175/6176698785_7dee72237e_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 3</figcaption>
</figure>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="https://farm6.staticflickr.com/5023/5578283926_822e5e5791_b.jpg" itemprop="contentUrl" data-size="1024x768">
<img src="https://farm6.staticflickr.com/5023/5578283926_822e5e5791_m.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption 4</figcaption>
</figure>
</div>
<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
<!-- Background of PhotoSwipe.
It's a separate element, as animating opacity is faster than rgba(). -->
<div class="pswp__bg"></div>
<!-- Slides wrapper with overflow:hidden. -->
<div class="pswp__scroll-wrap">
<!-- Container that holds slides. PhotoSwipe keeps only 3 slides in DOM to save memory. -->
<!-- don't modify these 3 pswp__item elements, data is added later on. -->
<div class="pswp__container">
<div class="pswp__item"></div>
<div class="pswp__item"></div>
<div class="pswp__item"></div>
</div>
<!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
<div class="pswp__ui pswp__ui--hidden">
<div class="pswp__top-bar">
<!-- Controls are self-explanatory. Order can be changed. -->
<div class="pswp__counter"></div>
<button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
<button class="pswp__button pswp__button--share" title="Share"></button>
<button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>
<button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>
<!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
<!-- element will get class pswp__preloader--active when preloader is running -->
<div class="pswp__preloader">
<div class="pswp__preloader__icn">
<div class="pswp__preloader__cut">
<div class="pswp__preloader__donut"></div>
</div>
</div>
</div>
</div>
<div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
<div class="pswp__share-tooltip"></div>
</div>
<button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
</button>
<button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
</button>
<div class="pswp__caption">
<div class="pswp__caption__center"></div>
</div>
</div>
</div>
</div>

Can't figure out why :nth-of-type won't work

I'm trying to select every 4th image in my div gallery. I can't seem to figure out why I can't select it.
#gallery img:nth-of-type(4n){
border: 5px solid #000;
}
I've tried a few other ideas but to no success. Can anyone help me and explain to me why this isn't selecting every 4th image in my div gallery? Thanks in advance.
<div id="gallery">
<a href="/system/images/series_uploads/5/original/ankara_5602p_alabaster.jpg?1330114093" rel="lightbox['gallery']">
<img alt="" src="/system/images/series_uploads/5/gallery/ankara_5602p_alabaster.jpg?1330114093" title="Ankara" />
<div class="gallery-text">
<h3>Ankara</h3>
<p>Porcelain</p>
</div>
</a>
<a href="/system/images/series_uploads/6/original/ankara_5624p_noce.jpg?1330114095" rel="lightbox['gallery']">
<img alt="" src="/system/images/series_uploads/6/gallery/ankara_5624p_noce.jpg?1330114095" title="Ankara" />
<div class="gallery-text">
<h3>Ankara</h3>
<p>Porcelain</p>
</div>
</a>
<a href="/system/images/series_uploads/7/original/ashton_23931_smokey_beige_.jpg?1330114250" rel="lightbox['gallery']">
<img alt="" src="/system/images/series_uploads/7/gallery/ashton_23931_smokey_beige_.jpg?1330114250" title="Ashton" />
<div class="gallery-text">
<h3>Ashton</h3>
<p>Porcelain</p>
</div>
</a>
<a href="/system/images/series_uploads/8/original/ashton_23942_camel_haze_entry.jpg?1330114251" rel="lightbox['gallery']">
<img alt="" src="/system/images/series_uploads/8/gallery/ashton_23942_camel_haze_entry.jpg?1330114251" title="Ashton" />
<div class="gallery-text">
<h3>Ashton</h3>
<p>Porcelain</p>
</div>
</a>
<a href="/system/images/series_uploads/9/original/ashton_23942_camel_haze_lr.jpg?1330114252" rel="lightbox['gallery']">
<img alt="" src="/system/images/series_uploads/9/gallery/ashton_23942_camel_haze_lr.jpg?1330114252" title="Ashton" />
<div class="gallery-text">
<h3>Ashton</h3>
<p>Porcelain</p>
</div>
</a>
<a href="/system/images/series_uploads/10/original/berkshire_25525_oak.jpg?1330115116" rel="lightbox['gallery']">
<img alt="" src="/system/images/series_uploads/10/gallery/berkshire_25525_oak.jpg?1330115116" title="Berkshire" />
<div class="gallery-text">
<h3>Berkshire</h3>
<p>HDP – High Definition Porcelain</p>
</div>
</a>
<a href="/system/images/series_uploads/11/original/berkshire_25585_walnut_famousdaves01.jpg?1330115118" rel="lightbox['gallery']">
<img alt="" src="/system/images/series_uploads/11/gallery/berkshire_25585_walnut_famousdaves01.jpg?1330115118" title="Berkshire" />
<div class="gallery-text">
<h3>Berkshire</h3>
<p>HDP – High Definition Porcelain</p>
</div>
</a>
</div>
they aren't siblings that's why you should use
#gallery a:nth-of-type(4n) img{
border: 5px solid #000;
}

Resources