Skip to content

Lightbox setup for single images without <a> tag #316

Answered by sogrbilja
igor-baiborodine asked this question in Q&A
Discussion options

You must be logged in to vote

Hi,

Can your Simple Lightbox be used for single images without a <a> tag?

For example:

<p>
<img src="<path-to-image>" alt="<image-description">
</p>

I tried this setup, but it does not work:

new SimpleLightbox('p img', {
    sourceAttr:'img'
});

After examining what isValidLink I concluded that it can be done! Look:

<div id="contmax">
  <span data-large="https://simplelightbox.js.org/img/full/02.jpg">
    <img draggable="false" style="padding: 5px" src="https://simplelightbox.js.org/img/thumb/02.jpg" />
  </span>
</div>

<script>
	let gallery = new SimpleLightbox('#contmax span', {"sourceAttr": "data-large"});
</script>

You "just" need to specify another attribute with the sourceAttr …

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by igor-baiborodine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants