How To Create A Modal In Javascript and CSS

Поделиться
HTML-код
  • Опубликовано: 17 окт 2024
  • Today we are going to learn how to create a simple modal in javascript and css. Feel free to edit the modal the way you want. This tutorial does not use Bootstrap or any other css frameworks or javascript frameworks.
    ~-~~-~~~-~~-~
    Follow my Twitter:
    / deved94
    Please watch: "Should You Become A Software Engineer?"
    • Video
    ~-~~-~~~-~~-~

Комментарии • 131

  • @siamonadi7997
    @siamonadi7997 5 лет назад +7

    you don't need an additional container div to darken other things up, this can be done with the box-shadow property;
    sth like this will do the trick : box-shadow: 0px 0px 0px 100vw rgba(0,0,0,0.6);
    apply this on your box an you wont need the container.
    great video ,thanks

    • @Wanderer2035
      @Wanderer2035 Год назад

      And when the demon came into our world, he blocked out the sun, and we were all engulfed in his shadow.

  • @leoMC4384
    @leoMC4384 2 года назад

    I'm rebuilding the frontend of this full stack project without Bootstrap. I hate dealing with CSS but I must learn to work with it if I have to. One of the things to replace are modals. Thank you so much. 👏👏👏

  • @andrewkamoha4666
    @andrewkamoha4666 2 года назад

    Would the tag simplify this tutorial?

  • @laurathomazi
    @laurathomazi 3 года назад +5

    I just love your tutorials, it's so easy to learn and your personality makes it even better. Really fun. Thank You

  • @fernandozamora6127
    @fernandozamora6127 2 года назад

    Bro you saved my life with this! I just kinda gave up and stared at my screen for an hour but now I see what I was doing wrong! Thank you!!

    • @Wanderer2035
      @Wanderer2035 Год назад

      I’d recommend watching the tutorial on it first, then after you have an idea practice building it on your own, instead of building it on your own before you watch the tutorial. It will save you from losing your hair.

  • @wisdomelue
    @wisdomelue 3 года назад +1

    i've watched 3 different tutorials for this, seems so hard, can't believe it's this simple, thanks man.

  • @adeisaac
    @adeisaac 4 года назад +2

    I have watched Dev's videos, and although he sound very very unserious, he is very very helpful. Thanks man, your Javascript course was very helpful.

  • @tawongachauluntha2880
    @tawongachauluntha2880 2 года назад

    Finally I have managed to create a modal with js .. thanks man

  • @pratyushkumar5740
    @pratyushkumar5740 2 года назад +1

    Awesome, I'll be integrating this for my production grade application. Thankyou so much.

  • @magalyriera
    @magalyriera 2 года назад

    Thank you for putting this video together! you are an excellent teacher! Greetings from Ecuador

  • @denciosantos5316
    @denciosantos5316 3 года назад

    hi am new in web development i just got your lesson very straight forward approach very nice.

  • @Onomandah
    @Onomandah 3 года назад

    Hey! Just wanted to say that I really appreciate your work and your sense of humor! :)

  • @jennamaegabriel
    @jennamaegabriel 3 года назад +2

    OMYG. IT WORKED 😭 Thank you for this, sir!

  • @MissAndieG21
    @MissAndieG21 4 года назад +4

    This was a really cool and easy way to use JavaScript.
    Thank you!

  • @prophetgadedemdzomeku3034
    @prophetgadedemdzomeku3034 3 года назад

    Your videos are very simple and you explain really well. You make Js very much interactive. Even 2021 this is the best Tutorial i have seen. Thanks. I want to know how i can get the complete course.

  • @damendiaye3440
    @damendiaye3440 3 года назад

    Thank you so simple so undestandable good job teacher

  • @abdianrizkyramadan1535
    @abdianrizkyramadan1535 3 года назад +2

    Love this man🤙 if i need any component, i watch your tutorial

  • @GiancarloCarccamo
    @GiancarloCarccamo 4 года назад +3

    Thanks bro for sharing your knowlegde with us, Saludos desde Honduras.

  • @t4vex2
    @t4vex2 11 месяцев назад

    congrats man, what a tutorial

  • @Telugupuranalu
    @Telugupuranalu 3 года назад

    Really.. awesome like very helpful for me 💗
    Love you too all your

  • @ChampagneRaji
    @ChampagneRaji 5 лет назад +8

    Dope! Thanks a lot for this man! Super easy to follow for a beginner like me haha

  • @NNNedlog
    @NNNedlog 3 года назад

    Thanks a lot Dev. Ed. You're the best

  • @ZANES-YT
    @ZANES-YT 3 года назад +1

    thank you so much you helped me out with a school project and I learned something new!

  • @jerryleemelton1860
    @jerryleemelton1860 2 года назад

    Dude, thanks so much for this! This was quick and easy and worked like a charm.

  • @haobamjameskumar3962
    @haobamjameskumar3962 4 года назад

    Best teacher ever

  • @callmequeen17
    @callmequeen17 3 года назад +1

    the papa bless made my heart happy c:

  • @f450fpv7
    @f450fpv7 5 месяцев назад

    Thank you for sharing your knowledge!
    Congratulations on your talent in making what is difficult to learn easy to learn for people like me who are just starting out.

  • @teymurnasirli
    @teymurnasirli 4 года назад +1

    It is a great tutorial simple explanation and a great approach. It will be better also show us how to apply the close event when the user click the outside of the module

  • @raulsantandertirado4400
    @raulsantandertirado4400 4 года назад +1

    Perhaps you could add the functionality of closing the modal by clicking outside of it?

  • @ldawg214
    @ldawg214 5 лет назад +2

    I've been really digging your videos. I do have a question though. How easy would it be to use this for multiple modals? For example, I'm creating my portfolio and I have a total of six projects listed on the home page and I'd like to fire a different modal for each project. This is awesome but it's only good for one modal and I'm trying to wrap my head around how to create multiple modals without going overboard in the code. Anyway, great work. Your videos are very engaging and entertaining.

    • @developedbyed
      @developedbyed  5 лет назад +2

      If all your modals are similar ( 1 header and paragraph etc). You could just use one modal in your html. When you want to have a different one you could change the textContent of them with javascript. Otherwise you would pretty much have to create multiple html modals and show and hide them with js.

    • @zahradeenie
      @zahradeenie 4 года назад

      @@developedbyed It would be great if you could do a part-two on the multiple modals - can't find anything online that explains how to do it as simply as you do

    • @Bayo106
      @Bayo106 4 года назад

      @@zahradeenie you don't need multiple. Just one modal and change the contents dynamically with JavaScript

    • @adarshtiwari7395
      @adarshtiwari7395 3 года назад

      I have the exact same requirements. Did you find a potential solution? Could you help me if you did?

  • @santiagoventura3211
    @santiagoventura3211 4 года назад

    Genio! te sigo desde Argentina y a pesar qu eno entienda muy bien ingles, disfruto muho tus videos.

  • @charbelmedia3014
    @charbelmedia3014 4 года назад +4

    Dev: Nothing does anything
    Me: Anything does Nothing
    Love your video bro! Ignore that I just made fun of you coz this video helped me a lot.
    I'm serious 😑😶😐

  • @RameenFallschirmjager
    @RameenFallschirmjager 5 лет назад +5

    you code butter smooth bro!

  • @sadstar7520
    @sadstar7520 2 года назад

    Thank you for sharing Ed 😂 don't be too nervous dude !!

  • @agu4071
    @agu4071 3 года назад

    i got a problem.. i have modal with some photos that can be closed by clicking on its background, but when i open one photo (opens as another modal) and close it by clicking its background I cant close the first modal by clicking its background. It works only when i don't open any photo. Am I doing something wrong? maybe its not good to make modal in modal or something..
    i use for both modals (with different names obviously):
    window.onclick = function closeModal (event)
    {
    if (event.target == imgModalBg)
    {
    imgModalBg.style.display = 'none';
    }
    }

  • @amandioreal2293
    @amandioreal2293 3 года назад

    Hi I'm tryning to show in a modal the value of a item inside a list group. Can you help in this?

  • @MrsLalaina
    @MrsLalaina 3 года назад

    Hello !
    Thanks, that's great !, now how to make it responsive?

  • @mugambo5505
    @mugambo5505 2 года назад

    Great vedio

  • @thegoat23452
    @thegoat23452 4 года назад

    Thanks Dev Ed for all

  • @NicolasCoutinho-l5f
    @NicolasCoutinho-l5f 3 года назад +1

    Thanks, buddy, I was having a hard time before watching your video. And again, thanks bro.

  • @muhammadabdelbari9128
    @muhammadabdelbari9128 2 года назад

    absolutely helpful thanks a lot

  • @coolguy9616
    @coolguy9616 2 года назад

    Hey man you are the best

  • @mojr6874
    @mojr6874 4 года назад

    Wow you are the master man I really appreciate your work your videos really help me

  • @fzrahmadan
    @fzrahmadan 2 года назад

    thanks man, i really appreciate it!

  • @shahbokhari
    @shahbokhari 5 лет назад +1

    Hi Ed, what if you use the modal class to multiple elements of the page for different content to show up in the modal itself. Making it a reusable modal. How would you go about that? Could you please make a tutorial about that. Thank You so much

    • @shazbaz5695
      @shazbaz5695 4 года назад

      did you figure it out?

    • @Bayo106
      @Bayo106 4 года назад

      I'm guessing you'll create an array of objects with information, then forEach of those add an event listener so that when they're clicked on, or whatever, the contents of the modal will be specific to each object

  • @felipefonseca9281
    @felipefonseca9281 3 года назад

    I want to say so many thanks! Very helpful! I

  • @galipruz1690
    @galipruz1690 2 года назад

    amazing man! thank you!

  • @aishikaroy6484
    @aishikaroy6484 4 года назад

    Can I just use modal to make a basic light box?

  • @rault8611
    @rault8611 6 лет назад +12

    why dont use display property css?

    • @developedbyed
      @developedbyed  6 лет назад +36

      great question! I don't use display: none because that cannot be transitioned. So we cannot have the "fade in effect" :)

    • @NNNedlog
      @NNNedlog 3 года назад

      @@developedbyed thanks for clearing my doubts Dev Ed. You're the best

  • @lisofsky8151
    @lisofsky8151 3 года назад

    Спасибо !!! то что нужно для понимания !! долго искал

  • @shazbaz5695
    @shazbaz5695 4 года назад +1

    It only works if the modal and the button are on the same page. What if you want the model and the button separated in two different HTML pages.. how do you get it to work then?

    • @michaelanderson6727
      @michaelanderson6727 3 года назад

      Include the html, javascript and css code in every page of your project. It's that simple. I hope you still need this

  • @tyassusanto9858
    @tyassusanto9858 2 года назад

    thankyou very much sir

  • @JustinPaulGT
    @JustinPaulGT 2 года назад

    Thank you bro 💓

  • @camilogarcia1325
    @camilogarcia1325 Год назад

    I have an array of objets with has properties, I want it show them on click event, but don´t no how to show e.target.value imagen with each object :s

  • @shubhambhatt329
    @shubhambhatt329 2 года назад

    thank u bro becz of i make this model

  • @adison2117
    @adison2117 3 года назад +1

    Is the visibility: hidden needed? Isnt just the opacity: 0 enough to hide the modal?

    • @GLimao
      @GLimao 3 года назад

      'cause if you put just opacity, all in the modal still there, but not visible, so the user can interact with everything there. It's like an invisible box. When you put the visibility: hidden, the modal is hidden, it's like is no modal there.
      And he use both, because one complement the other, and opacity is better for transition.
      I hope you can undertand this, I am not so good in english haha

    • @adison2117
      @adison2117 3 года назад

      Ok i see, but there is also pointer events: none which would do the same in combination of opacity and is more often used by people. So opacity would make the box invisible and pointer events would make it non interactive with a user. Am i right?

    • @GLimao
      @GLimao 3 года назад

      @@adison2117 yes, you can use pointer events and use just opacity

  • @GGanzolo
    @GGanzolo 3 года назад

    Thanks so much!

  • @evanilsonp.8183
    @evanilsonp.8183 2 года назад

    Amazing!

  • @allan4317
    @allan4317 2 года назад

    Nice pace of tutorial, except I would have liked to see the first (top) half of the CSS code so I could replicate everything while learning.

  • @deivi3697
    @deivi3697 2 года назад

    Why the X to close de modal top and right 10 px, always takes you to that point?

  • @urmilaroy2747
    @urmilaroy2747 4 года назад

    Please tell theme you used for this video

  • @joelgeleta2266
    @joelgeleta2266 4 года назад

    I am having troubles when i try to apply it to two buttons. The first one works fine but the second doesn't. Any help would be appreciated.

    • @omray7125
      @omray7125 4 года назад +2

      You would need to use document.querySelectorAll and use a for loop to go through all the indexes in the array that creates.

  • @xuanhuynh5952
    @xuanhuynh5952 4 года назад

    It's awesome. Thank you Ed.

  • @mohamedelkashef7771
    @mohamedelkashef7771 4 года назад

    You are amazing man keep going ❤️❤️❤️

  • @AAARONSD
    @AAARONSD 3 года назад

    Thanks for the upload. I followed the directions and code to make my first modal and it only seemed to work on Code Pen but as soon as I plugged it into Visual Studios Live Server it didnt work. Anyone know why?

    • @AAARONSD
      @AAARONSD 3 года назад

      The button is there but when I click it it does not open the modal.

  • @fabrice9403
    @fabrice9403 5 лет назад

    how can you add animation on like it comes from top to the center. and to click on an empty space to close it. how to do that?

  • @dexterdragons
    @dexterdragons 4 года назад

    hey, how to modal popup - createElement and innerHTML? open and close btn?

  • @priyankanispro
    @priyankanispro 2 года назад +4

    You can Use "×" for the Cross Sign. Ex:
    ×
    The Result will be like This: ×

  • @samueltorres2485
    @samueltorres2485 3 года назад

    This was helpful, thanks!

  • @sovereignlivingsoul
    @sovereignlivingsoul 4 года назад

    Nice video, maybe update with the arrow function. Thanks for sharing.

  • @dominicvolante1616
    @dominicvolante1616 3 года назад

    This is the easiest Modal I've ever seen

  • @heirsofchrist
    @heirsofchrist 4 года назад

    Big Bro, it really helped. Thanks.

  • @ferdinadcusihuamanayma2692
    @ferdinadcusihuamanayma2692 4 года назад

    thank you for your totorials!

  • @epizarro309
    @epizarro309 4 года назад

    Great video!

  • @stefaniaalbornozibanez3322
    @stefaniaalbornozibanez3322 4 года назад

    gracias capo te agradezco muchisimo

  • @ansariarbaz3374
    @ansariarbaz3374 4 года назад

    IT IS AWESOME

  • @anniely7311
    @anniely7311 5 лет назад +2

    From what I can tell, my code looks identical. However, none of the code, after hidden visibility including the js, seems to be working for me. Any pointers? No pun intended :D

    • @developedbyed
      @developedbyed  5 лет назад

      Can you copy paste your code on github?

    • @anniely7311
      @anniely7311 5 лет назад

      @@developedbyed Yes! Please follow this link. Thank you!
      github.com/annielly/balance

    • @uimonk
      @uimonk 5 лет назад

      ruclips.net/video/8A6mqAu4llg/видео.html
      this video has source code with explanation

  • @Christfemme
    @Christfemme 3 года назад +2

    This is great, and really helped me. However, I have 3 buttons that need to open 3 separate modals, and I although all three of them open (one at a time), I cannot get the last two to close.

  • @aljoeanthonyberdin2845
    @aljoeanthonyberdin2845 4 года назад

    Where did you get the .bg-active in CSS sir? im just a beginner I hope you notice my comment. Godbless! =)

    • @jamespawson6045
      @jamespawson6045 3 года назад

      You add/create the class in CSS and then use JavaScript classList.add to add it to the html element when the button is clicked.

  • @vishwajeetraj11
    @vishwajeetraj11 4 года назад

    yeah when the content overflows it doesnt show the header part of modal its chopped off.

  • @vartikadehalvi5664
    @vartikadehalvi5664 3 года назад

    how do we do it with gsap?

  • @stianhansen6738
    @stianhansen6738 4 года назад +3

    Thank you for your great tutorials! I wish you had the html and css code on github or similar for us to copy and paste. Would make it quite a bit easier to get into the js.

    • @amithshambu7181
      @amithshambu7181 3 года назад

      Yes yes yes yes, someone please help!!!!!!!!

  • @CheMansur
    @CheMansur 6 лет назад

    Helped alot, thanks :D

  • @ninadparkar6998
    @ninadparkar6998 3 года назад

    How to make modal unscrollable?

  • @sakshigoyal9018
    @sakshigoyal9018 3 года назад

    sir my js code is not working i am not getting why?

  • @richestboy_uz
    @richestboy_uz 3 года назад

    👍👍👍👍

  • @dilemma9865
    @dilemma9865 3 года назад

    ❤❤

  • @damolaadigun9574
    @damolaadigun9574 4 года назад

    i wanted the modal to be on top of my content but it keeps scattering the arrangement

  • @antoniosalzano5253
    @antoniosalzano5253 4 года назад +1

    i can't see the start of the css..

  • @BUDX
    @BUDX 4 года назад

    How to close the modal by clicking outside of it

    • @vishalasthana8998
      @vishalasthana8998 4 года назад

      window.addEventListener('click', (event) => {
      if(event.target === modal) {
      modal.classList.remove('bg-active');
      }
      });

  • @ectoplasm1285
    @ectoplasm1285 5 лет назад +1

    can you please share all of your css code ?

    • @uimonk
      @uimonk 5 лет назад

      ruclips.net/video/8A6mqAu4llg/видео.html
      this video has source code with explanation

  • @jojok.mikaka6955
    @jojok.mikaka6955 3 года назад

    please ! show us the start of css code !

  • @HK-sw3vi
    @HK-sw3vi 3 года назад

    les fucking gooooooooooooo!

  • @rohitkk1982
    @rohitkk1982 2 года назад

    Can you share the code

  • @bukqueiroz
    @bukqueiroz 3 года назад +1

    wtf what is the start css?????????????????????????????????????????????????????????????

  • @STXplague
    @STXplague 4 года назад

    Source code?

  • @sigmiami
    @sigmiami 4 года назад +7

    Didnt work

  • @ishaanpandey
    @ishaanpandey 3 года назад +1

    did not work for me 😭😭😭😭

  • @hesyashidiq1153
    @hesyashidiq1153 3 года назад

    thanks (^_^)/

  • @aligu7
    @aligu7 4 года назад

    Could you send me a source code please :)