How to Implement Lightbox on Bootstrap 4

in #utopian-io7 years ago (edited)

This is a simple tutorial on how to implement Lightbox in your project.

Lightbox is a simple JavaScript library that displays images or videos on the same page of a browser by filling part of the screen and dimming out the rest of the web page.

It is very helpful because it opens the image on your current web page instead of taking you to the link of the image.

How to Implement.

  • First, we set up our index.html file. And Add all the bootstrap link, as seen here or you can clone this bootstrap starter pack.
    $ git clone https://github.com/Rhotimee/bootstrap4-beta-starter-pack.git
  • Then we add the links to our images to the body of our HTML file. An example is shown below.
                    <a href="http://lrempixel.com/560/560/sports/2" 
                    data-toggle="lightbox" data-gallery="img-gallery">
                    <img src="http://lrempixel.com/400/400/sports/2" 
                    class="img-fluid">    
                    </a>

Make sure You specify that data-toggle = "lightbox"

  • Then, we to add lightbox ekko CSS & js cdn link to our index.html

Css

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ekko-lightbox/5.3.0/ekko-lightbox.css" />

Js

 <script src="https://cdnjs.cloudflare.com/ajax/libs/ekko-lightbox/5.3.0/ekko-lightbox.js"></script>
  • Create a Js file in your project, Link it to your Index.html then add the following code as seen below in the js file.
$(document).on('click', '[data-toggle="lightbox"]', function(event){
    event.preventDefault();
    $(this).ekkoLightbox();
});

  • Save. And reload your browser.

See Screenshot of the Browser:
Screen Shot 2018-01-08 at 1.38.22 PM.png

Screen Shot 2018-01-08 at 1.39.01 PM.png

Screen Shot 2018-01-08 at 1.39.15 PM.png

See full code in my Github Repo.
GITHUB: https://github.com/Rhotimee/lightbox-for-bootstrap

If you have any question or issue, I would be glad to help.

Enjoy!



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Hey @rhotimee I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x