Тёмный

Simple Image Lightbox Tutorial 

Web Dev Simplified
Подписаться 1,6 млн
Просмотров 80 тыс.
50% 1

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

Опубликовано:

 

30 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 107   
@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.
@cudakRS
@cudakRS 4 года назад
is it possible to add feature that allows use arrows on keyboard to scroll through images?
@rickhorton4955
@rickhorton4955 4 года назад
Thanks for a great video. How can we make a description appear in the lightbox with the image?
@stevemesser1635
@stevemesser1635 4 года назад
Absolutely excellent teacher! Thank you and keep up the good work.
@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!
@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!
@archaja
@archaja 9 месяцев назад
Hi! Would really like to work this out, but as soon as I put
@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 ?
@abdussamed107
@abdussamed107 8 месяцев назад
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?
@adritaislam7333
@adritaislam7333 3 года назад
How to use it in Vue js? Why it doesn't work in my vue application😭😭😭😭😭😭😭😭
@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.
@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') })
@reynaldoramos9564
@reynaldoramos9564 9 месяцев назад
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
@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?
@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.
@pixiedustdreams
@pixiedustdreams Год назад
I dont think i'll ever be able to learn what he teaches. I am so distracted by his face. 🤩
@AndyMorrisArt
@AndyMorrisArt 10 месяцев назад
Awesome! Now all I need to do is figure out left-right controls for the lightbox. Thanks!
@federicovenditti1324
@federicovenditti1324 2 года назад
ny javascript doesn't work
@SPOREFAN04XL
@SPOREFAN04XL 2 года назад
Thank you, Web Dev Simplified! The image gallery for my new portfolio website is now ready to go!
@TheNicoya77
@TheNicoya77 2 года назад
Cool, all i need to add is just next and previous button. Thanks
@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.
@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 ^^
@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! :)
@trayhorn
@trayhorn Год назад
Why do we need to add listeners to each image instead of set one listener to the div using delegation?
@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?
@taranjeet9
@taranjeet9 5 лет назад
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?
@WanderingProphet
@WanderingProphet 3 года назад
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?
@davshadou
@davshadou Год назад
At 9:20 what and where does the "e" in the event listener come from?
@franciscojunior8066
@franciscojunior8066 2 года назад
Wow!! Very, very good!! Thank you from Brazil my brother. ; ) You are awesome!
@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.
@ghury1
@ghury1 10 месяцев назад
how to open an lightbox with an in it?
@pedrodavi_05
@pedrodavi_05 Год назад
unbelievable, your channel of youtube is good of season, congrants man and continuos walk!
@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!
@ruslanlipoduk5268
@ruslanlipoduk5268 4 года назад
thankyou from stambul you thich wery good you know how can stay junior js deweloper
@cafe-con-leche
@cafe-con-leche 4 года назад
Thank you so much, im having super fun with your tutorials 👍👍👍
@kaydrum9377
@kaydrum9377 3 года назад
This is very helpful. Thank you so much!
@quentinblanc4326
@quentinblanc4326 3 года назад
Maybe you should mark time step in the description.
@sofianghazali8911
@sofianghazali8911 4 года назад
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?
@AzSaMwEE
@AzSaMwEE 4 месяца назад
bro i love you
@sashaahrens6045
@sashaahrens6045 3 года назад
absolute legend, this really got me to understand lightboxes thanks so much
@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!
@jefrisaragih390
@jefrisaragih390 3 года назад
Where is the code?
@atheerapeter5174
@atheerapeter5174 4 года назад
could've just done e.currentTarget.innerHTML=" "; in the lightbox event listener to clear images out of it
@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
@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.
@zachmurri
@zachmurri 3 года назад
this is great, very helpful, thank you
@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!
@sajidurrahmansahib70
@sajidurrahmansahib70 2 года назад
love U
@juiub
@juiub 3 года назад
hello im curious, how do you add figcaption to the images?
@keith6658
@keith6658 2 года назад
Great tutorial! But I don't get the Lightbox part to work :(
@fuchslochtv
@fuchslochtv 3 года назад
good one!
@Moe.firouzabadi
@Moe.firouzabadi 4 года назад
Are you using prettier? Thanks 🙏
@grownmancrying
@grownmancrying 5 лет назад
Thanks for this one, cool stuff!
@ostrymiszczu
@ostrymiszczu 4 года назад
Very clear, cool stuff. I will recommend your video to anyone who is looking for nice lightbox tutorial, thanks !
@Gormlessostrich
@Gormlessostrich 3 года назад
Superb tutorial as always. Thanks, Kyle!
@silvercrow289
@silvercrow289 2 года назад
Thenk you so much! This helped me a lot!
@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.
@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 5 лет назад
@@WebDevSimplified I think she wants a tutorial/video for this.
@WebDevSimplified
@WebDevSimplified 5 лет назад
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!
@zachfenton608
@zachfenton608 3 года назад
very well and it worked in my webpage
@绿叶-t7c
@绿叶-t7c 3 года назад
You are a teaching master! light and easy understand! Thank you!
@susilthapa4367
@susilthapa4367 4 года назад
this is awesome tutorial , thank you very much 🙏🙏
@Nathan-ki4qn
@Nathan-ki4qn 3 года назад
Very helpful and easy to understand.
@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
@denisrusu1984
@denisrusu1984 2 года назад
Спасибо большое. Выручил
@matismlr721
@matismlr721 3 года назад
thanks a lot mate :)
@valentynakovsanova2185
@valentynakovsanova2185 3 года назад
thank you so much, it helped a lot
@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.
@adamsDevArt
@adamsDevArt 4 года назад
Thanks man you rock!
@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.
@Tassaczek
@Tassaczek 3 года назад
Nice :D
@Kerimchaly
@Kerimchaly 4 года назад
U literally saved my life💪
@myam754
@myam754 4 года назад
Thanks a lot, Kyle!
@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..
@wongbejo6647
@wongbejo6647 5 лет назад
Great tutorial. Greeting from Indonesia
@WebDevSimplified
@WebDevSimplified 5 лет назад
Thank you!
@Y2L1029
@Y2L1029 5 лет назад
Just about to build a light box lol thanks
@WebDevSimplified
@WebDevSimplified 5 лет назад
You're welcome!
@haythemsaidi91
@haythemsaidi91 5 лет назад
Really helpfull, thanks a lot.
@WebDevSimplified
@WebDevSimplified 5 лет назад
You're welcome!
@nonsolovita
@nonsolovita 5 лет назад
I needed this thx Kyle :)
@WebDevSimplified
@WebDevSimplified 5 лет назад
You're welcome! I'm glad I could help.
@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); }
Далее
Create a CSS only lightbox using :target
34:08
Просмотров 68 тыс.
小路飞嫁祸姐姐搞破坏 #路飞#海贼王
00:45
OYUNCAK DİREKSİYON İLE ARABAYI SÜRDÜ 😱
00:16
Просмотров 2,7 млн
Ко мне подкатил бармен
00:58
Просмотров 186 тыс.
Build a Popup With JavaScript
16:55
Просмотров 369 тыс.
Please stop using px for font-size.
15:18
Просмотров 172 тыс.
Incredible scroll-based animations with CSS-only
32:23
Просмотров 442 тыс.
How To Make Tooltips With Only CSS
15:05
Просмотров 112 тыс.
These CSS PRO Tips & Tricks Will Blow Your Mind!
8:48
Просмотров 353 тыс.
Build this JS calculator in 15 minutes! 🖩
15:20
Просмотров 575 тыс.
Tutoriel JavaScript : Lightbox
56:13
Просмотров 19 тыс.