No video

Simple Image Lightbox Tutorial

  Рет қаралды 79,644

Web Dev Simplified

Web Dev Simplified

Күн бұрын

Image lightboxes are incredibly popular, especially in portfolio websites. Luckily, implementing a lightbox is much easier than it looks. In this video I will be breaking down exactly what a lightbox is and how to set one up using HTML, CSS, and JavaScript. I will also be discussing exactly why I write each line of code as well as potential alternative options as I go. By the end of this video you will have a fully working lightbox example ready to add into your own applications.
📚 Materials/References:
- CSS Grid Tutorial: • Learn CSS Grid in 20 M...
- Defer vs Async Tutotorial: • What Is The Fastest Wa...
- GitHub Code: github.com/Web...
- CodePen Code: codepen.io/Web...
🧠 Concepts Covered:
- How to dynamically create HTML elements
- How position fixed works
- Showing/hiding HTML elements
- Setting up event listeners
- CSS grid
🌎 Find Me Here:
My Website: webdevsimplifi...
Patreon: / webdevsimplified
Twitter: / devsimplified
Discord: / discord
GitHub: github.com/Web...
CodePen: codepen.io/Web...
#Lightbox #WDS #ImageLightbox

Пікірлер: 108
@WebDevSimplified
@WebDevSimplified 5 жыл бұрын
Join the Discord server to help influence future video topics. discord.gg/7StTjnR
@toma1610
@toma1610 3 жыл бұрын
I look forward for the second part. How to add arrows for next a prev, the X to close the main canvas image and how to add title an caption to each image.
@AtacamaHumanoid
@AtacamaHumanoid Жыл бұрын
And the third part where he makes the thumbnails smaller images so it loads faster. And also explains how to automatically generate small images when the client uploads large images into the gallery :) ...but there were some great tips in here I learned from even if the gallery is really only something you could sell on Fiverr.
@toma1610
@toma1610 Жыл бұрын
@@AtacamaHumanoid I have all that, I‘ll see how do I upload to github.
@Smashley127
@Smashley127 2 жыл бұрын
I've been sifting through MANY lightbox tutorials, and yours was the one that got me to successfully create one! Thank you so much!
@ReadyDaddy
@ReadyDaddy 2 жыл бұрын
Wow, there's at least 50 "image gallery" videos i've seen in last few hours, mindlessly searching to find something that can help my project but no video helped, literally everyone BUT YOU is doing something very niche that can't really be used for already existing projects. You are a light in the darkness, simple and VERY CUSTOMIZABLE!!! Love it man, big respect!
@reds.webdesign.2966
@reds.webdesign.2966 Жыл бұрын
Lifesaver. Thank you! I had also my logo and other images pop up in the lightbox so I gave the respective images that I wanted to target a classname "lbimg" and targeted them using const images = document.querySelectorAll(".lbimg") For anyone looking for the code: CSS: #lightbox{ position: fixed; z-index:100; top:0; width: 100%; height: 100%; background-color: rgba(0,0,0,.8); display:none; } #lightbox.active{ display: flex; justify-content: center; align-items: center; } #lightbox img{ max-width:90%; max-height:80%; padding:4px; background-color: black; border:4px solid var(--font-color); } JavaScript: const lightbox = document.createElement('div') lightbox.id ='lightbox' document.body.appendChild(lightbox) const images = document.querySelectorAll("img") images.forEach(image => { image.addEventListener('click',e => { lightbox.classList.add('active') const img = document.createElement('img') img.src = image.src while(lightbox.firstChild){ lightbox.removeChild(lightbox.firstChild) } lightbox.appendChild(img) }) }) lightbox.addEventListener('click', e => { if(e.target !== e.currentTarget) return lightbox.classList.remove('active') })
@stevemesser1635
@stevemesser1635 4 жыл бұрын
Absolutely excellent teacher! Thank you and keep up the good work.
@sherifsalah5563
@sherifsalah5563 5 жыл бұрын
Your solutions for those two bugs are genius .. you always amaze me.
@WebDevSimplified
@WebDevSimplified 5 жыл бұрын
Thank you! Years of practice and debugging definitely help.
@AndyMorrisArt
@AndyMorrisArt 9 ай бұрын
Awesome! Now all I need to do is figure out left-right controls for the lightbox. Thanks!
@FuzzyImages
@FuzzyImages 2 жыл бұрын
I'm not sure why this was so finicky when it came to joining it with bootstrap elements, but once completed they suddenly work, so thanks very much, big life saver ^^
@SPOREFAN04XL
@SPOREFAN04XL 2 жыл бұрын
Thank you, Web Dev Simplified! The image gallery for my new portfolio website is now ready to go!
@BGP_23
@BGP_23 2 жыл бұрын
Thank you so much for sharing this, I am learning front end and this was a perfect explanation to help me with a class project. Don't let it be said that old dogs can't learn new tricks...lol I am 50.
@EndTimeCountryLiving
@EndTimeCountryLiving 3 жыл бұрын
That is super awesome Kyle. I really like your style of doing things. Simple, clean, and concise code.
@sonoftroy8572
@sonoftroy8572 5 жыл бұрын
This allows me to possibly make changes to my code, I really appreciate this lightbox tutorial thanks
@WebDevSimplified
@WebDevSimplified 5 жыл бұрын
You're welcome! I'm glad you enjoyed it.
@sashaahrens6045
@sashaahrens6045 3 жыл бұрын
absolute legend, this really got me to understand lightboxes thanks so much
@pedrodavi_05
@pedrodavi_05 Жыл бұрын
unbelievable, your channel of youtube is good of season, congrants man and continuos walk!
@LucasFGodoy
@LucasFGodoy 3 жыл бұрын
very easy and simple! I could easily adapt to my testing page. I wonder, however, if it would be too complicated to add previous and next buttons? good job!
@cudakRS
@cudakRS 4 жыл бұрын
is it possible to add feature that allows use arrows on keyboard to scroll through images?
@ostrymiszczu
@ostrymiszczu 4 жыл бұрын
Very clear, cool stuff. I will recommend your video to anyone who is looking for nice lightbox tutorial, thanks !
@user-pg5kn5mb6y
@user-pg5kn5mb6y 3 жыл бұрын
You are a teaching master! light and easy understand! Thank you!
@franciscojunior8066
@franciscojunior8066 Жыл бұрын
Wow!! Very, very good!! Thank you from Brazil my brother. ; ) You are awesome!
@TheNicoya77
@TheNicoya77 2 жыл бұрын
Cool, all i need to add is just next and previous button. Thanks
@cafe-con-leche
@cafe-con-leche 4 жыл бұрын
Thank you so much, im having super fun with your tutorials 👍👍👍
@rickhorton4955
@rickhorton4955 4 жыл бұрын
Thanks for a great video. How can we make a description appear in the lightbox with the image?
@carlonnrivers
@carlonnrivers 5 жыл бұрын
Wow this seems very simple and a cool idea! I can definitely use this on my website when viewing user's profile pictures or images in messages!!
@WebDevSimplified
@WebDevSimplified 5 жыл бұрын
I'm glad you found the video useful. I hope everything goes well when you implement this in your own site.
@Gormlessostrich
@Gormlessostrich 3 жыл бұрын
Superb tutorial as always. Thanks, Kyle!
@richardlugier3659
@richardlugier3659 4 жыл бұрын
C'est un tuto très bien expliqué et assez simple à mettre en oeuvre. It's a good tutorial and i appreciated. Great
@silvercrow289
@silvercrow289 2 жыл бұрын
Thenk you so much! This helped me a lot!
@kaydrum9377
@kaydrum9377 3 жыл бұрын
This is very helpful. Thank you so much!
@reynaldoramos9564
@reynaldoramos9564 8 ай бұрын
Thanks for the interesting and helpful tutorial. Is there a way to add a swipe capability? For example, if you swipe left or right on a touch device or use the mouse/arrow keys to transition from one image to another. Thanks
@Nathan-ki4qn
@Nathan-ki4qn 3 жыл бұрын
Very helpful and easy to understand.
@grownmancrying
@grownmancrying 4 жыл бұрын
Thanks for this one, cool stuff!
@zachfenton608
@zachfenton608 3 жыл бұрын
very well and it worked in my webpage
@MrMihov
@MrMihov 4 жыл бұрын
Numero 1! Thanks a lot! Everything simple and clear, hands-down the best dev-tutor imho. You made me uninstall wordpress and remake my portfolio with code. Do you plan to make a similar tutorial but for embedded youtube/vimeo player in a lightbox. I've managed to make it work just by following this tutorial and a codepen but I am super curious how you'ld do it from skratch. Thanks again!
@zachmurri
@zachmurri 3 жыл бұрын
this is great, very helpful, thank you
@susilthapa4367
@susilthapa4367 4 жыл бұрын
this is awesome tutorial , thank you very much 🙏🙏
@AnnieTaylorChen
@AnnieTaylorChen 5 жыл бұрын
Nice ! I have always wanted to do this, now I should also try to think how to implement it in react. :D
@WebDevSimplified
@WebDevSimplified 5 жыл бұрын
It hopefully shouldn't be too hard to get working with React. It will take quite a bit different code to do it though.
@rymisoda
@rymisoda 4 жыл бұрын
Thanks for this fantastic tutorial! It helped me out a ton. Are you using an extension that allows you to skip semicolons at the ends of lines in your JavaScript?
@soensaid
@soensaid 4 жыл бұрын
semi colons are not needed in javascript and if youre using the prettier extension in vs code then you can change the settings to not add semicolons when it formats your code.
@adamsDevArt
@adamsDevArt 4 жыл бұрын
Thanks man you rock!
@fuchslochtv
@fuchslochtv 3 жыл бұрын
good one!
@valentynakovsanova2185
@valentynakovsanova2185 3 жыл бұрын
thank you so much, it helped a lot
@trayhorn
@trayhorn Жыл бұрын
Why do we need to add listeners to each image instead of set one listener to the div using delegation?
@myam754
@myam754 4 жыл бұрын
Thanks a lot, Kyle!
@Kerimchaly
@Kerimchaly 4 жыл бұрын
U literally saved my life💪
@cocodemongaming8135
@cocodemongaming8135 Жыл бұрын
Hey, this tutorial really helped me understand it better than my tutor did at university. however, mine isn't responsive, how do I fix this please anyone?
@nonsolovita
@nonsolovita 5 жыл бұрын
I needed this thx Kyle :)
@WebDevSimplified
@WebDevSimplified 5 жыл бұрын
You're welcome! I'm glad I could help.
@DavidAshby1
@DavidAshby1 3 жыл бұрын
Great tutorial and works a treat. In a reply to someones comments you said you may consider doing a gallery with next and back buttons on the lightbox image, have you done one or did you decide against it? I would just like to add next and previous buttons to the image but from the research so far, I would need to start from scratch. Surely there is a way to add in this feature using the code you have given in this tutorial? Thanks again.
@abdussamed107
@abdussamed107 7 ай бұрын
Thanks for sharing. Would it be possible to load this gallery inside an but enlarge the image to Full-Screen size (100% of browser viewport) once clicked? Does someone have an idea?
@kenzafilali9115
@kenzafilali9115 2 жыл бұрын
i want to do the same thing though i want to select all elemnet with href that finishes with jpg in the document i did this let links = document.querySelectorAll('[href$=".jpg"],[href$=".mp4"]') yet i have errror saying that "links " is not defined where is the probleme ?
@AzSaMwEE
@AzSaMwEE 3 ай бұрын
bro i love you
@archaja
@archaja 8 ай бұрын
Hi! Would really like to work this out, but as soon as I put
@davshadou
@davshadou Жыл бұрын
At 9:20 what and where does the "e" in the event listener come from?
@matismlr721
@matismlr721 3 жыл бұрын
thanks a lot mate :)
@Mohamedtarek-qz2zj
@Mohamedtarek-qz2zj 5 жыл бұрын
awesome greaaaaat contentism but can we add a slider
@WebDevSimplified
@WebDevSimplified 5 жыл бұрын
You can definitely add a slider if you want. I may cover one in the future as well.
@ginevrafonteswilliams3987
@ginevrafonteswilliams3987 4 жыл бұрын
@@WebDevSimplified hello, can you please share the code to add the slider? :) you would be a life saver!
@WanderingProphet
@WanderingProphet 2 жыл бұрын
Thank you so much for this great tutorial. Now, my gallery is a bit different from yours. I'm not using the tag. Instead, I'm using background-image. I made a div with a class name, and with that class name I made a selector and then .className { background-image: url("images/imageName.jpg") }. Because I'm not using , I'm not using src, so img.src = image.src won't work, would it, when trying to get images for the Lightbox? And another thing, it's great that you're able to style the image on Lightbox, putting a border around it and whatnot. Is it possible to put captions underneath the image when it's on Lightbox?
@djolo5140
@djolo5140 3 жыл бұрын
how to make the selector for only the images inside the grid?
@haythemsaidi91
@haythemsaidi91 5 жыл бұрын
Really helpfull, thanks a lot.
@WebDevSimplified
@WebDevSimplified 5 жыл бұрын
You're welcome!
@denisrusu1984
@denisrusu1984 2 жыл бұрын
Спасибо большое. Выручил
@adritaislam7333
@adritaislam7333 3 жыл бұрын
How to use it in Vue js? Why it doesn't work in my vue application😭😭😭😭😭😭😭😭
@wongbejo6647
@wongbejo6647 5 жыл бұрын
Great tutorial. Greeting from Indonesia
@WebDevSimplified
@WebDevSimplified 5 жыл бұрын
Thank you!
@juiub
@juiub 3 жыл бұрын
hello im curious, how do you add figcaption to the images?
@sofianghazali8911
@sofianghazali8911 3 жыл бұрын
I tried implementing your tutorial. After clicking on first image, it works fine. However, when I do it for the second and third, the webpage becomes unresponsive. Any ideas on how to fix it?
@pixiedustdreams
@pixiedustdreams 11 ай бұрын
I dont think i'll ever be able to learn what he teaches. I am so distracted by his face. 🤩
@taranjeet9
@taranjeet9 4 жыл бұрын
Can You Make Few Videos? I Have Some Ideas and Needs Help. 1. How Can i Create a Blog using HTML/CSS/JS etc Without WordPress. But Similar. i Have 150+ Posts and How Can i Add Them Easily? 2. How Can I add Schema in WordPress or HTML Website Manually? Or How to Add Schema Manually which Yoast SEO adds Automatically?
@keith6658
@keith6658 2 жыл бұрын
Great tutorial! But I don't get the Lightbox part to work :(
@Y2L1029
@Y2L1029 5 жыл бұрын
Just about to build a light box lol thanks
@WebDevSimplified
@WebDevSimplified 5 жыл бұрын
You're welcome!
@ponding
@ponding 4 жыл бұрын
What if the image you are attempting to load into the lightbox is a completely different image? For example, the thumbnail is 300x300 but it's lightbox image is a 320x720?
@ponding
@ponding 4 жыл бұрын
I got what I wanted by applying 0.0 opacity to the thumbnails and creating a background image for each div in question. Just wanted to know if there was an easier way.
@BlueMochi9
@BlueMochi9 3 жыл бұрын
I typed in everything word for word but it's not working! What do I do, like I got my images in a grid but that's about it when I click on them nothing happens. Do I need to add a jquery cdn or something?
@keith6658
@keith6658 2 жыл бұрын
I´m having the exact problem ! :( did you solve it?
@oblivion6672
@oblivion6672 5 жыл бұрын
Why didn't you make it like a full-on gallery? Where you could go to the next img and prev img. Next video maybe?
@WebDevSimplified
@WebDevSimplified 5 жыл бұрын
I didn't want to add extra stuff to this tutorial since it was purely about building a lightbox feature and not a gallery. I view these as two different features that many times are used together, but not always. I do plan to cover a gallery at some point though.
@ginevrafonteswilliams3987
@ginevrafonteswilliams3987 4 жыл бұрын
@@WebDevSimplified Please do! :)
@quentinblanc4326
@quentinblanc4326 3 жыл бұрын
Maybe you should mark time step in the description.
@Tassaczek
@Tassaczek 3 жыл бұрын
Nice :D
@luberalexanderechavarriabe4156
@luberalexanderechavarriabe4156 3 жыл бұрын
@t Hi Kail , I have learning from your videos for a while and they are so good. I just wanted to share what i did with next.js which has similar functionality to what you do in this video . Maybe it could be handy for someone
@ruslanlipoduk5268
@ruslanlipoduk5268 4 жыл бұрын
thankyou from stambul you thich wery good you know how can stay junior js deweloper
@maskman4821
@maskman4821 5 жыл бұрын
can we build image lightbox with reactjs ???
@WebDevSimplified
@WebDevSimplified 5 жыл бұрын
Of course. Your code will be quite a bit different for the JS but it is possible for sure.
@Colstonewall
@Colstonewall 4 жыл бұрын
@@WebDevSimplified I think she wants a tutorial/video for this.
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
I probably won't do a tutorial on this since the code is nearly identical just with Reqct sprinkled in.
@income_taxes
@income_taxes 4 жыл бұрын
@@WebDevSimplified please do one with REACT!
@atheerapeter5174
@atheerapeter5174 4 жыл бұрын
could've just done e.currentTarget.innerHTML=" "; in the lightbox event listener to clear images out of it
@jefrisaragih390
@jefrisaragih390 3 жыл бұрын
Where is the code?
@sajidurrahmansahib70
@sajidurrahmansahib70 2 жыл бұрын
love U
@ghury1
@ghury1 9 ай бұрын
how to open an lightbox with an in it?
@federicovenditti1324
@federicovenditti1324 2 жыл бұрын
ny javascript doesn't work
@Moe.firouzabadi
@Moe.firouzabadi 4 жыл бұрын
Are you using prettier? Thanks 🙏
@RoshanKrSoni
@RoshanKrSoni 5 жыл бұрын
Where is ReactJs next tutorial? 😐
@WebDevSimplified
@WebDevSimplified 5 жыл бұрын
It is coming. Those tutorials take quite a bit longer and I have been really busy.
@RoshanKrSoni
@RoshanKrSoni 5 жыл бұрын
@@WebDevSimplified no problem 😊 we will be waiting..
@Coding_Asmr_PraDev
@Coding_Asmr_PraDev 5 жыл бұрын
1st brother
@moonsdonut5188
@moonsdonut5188 5 жыл бұрын
var blue stinger guy = "web Dev Simplified"{ function Give like console.log(isAwsome); }
WTF Do These Even Mean
13:44
Web Dev Simplified
Рет қаралды 84 М.
JS-плагины №6. Галерея фотографий и видео с помощью Fslightbox.js
22:20
КАКУЮ ДВЕРЬ ВЫБРАТЬ? 😂 #Shorts
00:45
НУБАСТЕР
Рет қаралды 3,5 МЛН
Oh No! My Doll Fell In The Dirt🤧💩
00:17
ToolTastic
Рет қаралды 12 МЛН
7 Days Stranded In A Cave
17:59
MrBeast
Рет қаралды 97 МЛН
These CSS PRO Tips & Tricks Will Blow Your Mind!
8:48
Coding2GO
Рет қаралды 260 М.
The problems with viewport units
13:23
Kevin Powell
Рет қаралды 360 М.
How to Make Photo Studio For Professional Product Photography at Home
8:26
How To Create An Animated Image Carousel With CSS/JavaScript
14:10
Web Dev Simplified
Рет қаралды 268 М.
Learn Sass In 20 Minutes | Sass Crash Course
19:42
developedbyed
Рет қаралды 933 М.
Top 10 CSS One Liners That Will Blow Your Mind
13:34
developedbyed
Рет қаралды 945 М.
How To Make Tooltips With Only CSS
15:05
Web Dev Simplified
Рет қаралды 111 М.
Using CSS custom properties like this is a waste
16:12
Kevin Powell
Рет қаралды 168 М.