How To Create A Modal In Javascript and CSS

แชร์
ฝัง
  • เผยแพร่เมื่อ 17 มิ.ย. 2018
  • 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

  • @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

  • @raajankumar4390
    @raajankumar4390 5 ปีที่แล้ว +8

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

  • @wisdomelue
    @wisdomelue 3 ปีที่แล้ว +1

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

  • @MissAndieG21
    @MissAndieG21 4 ปีที่แล้ว +4

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

  • @jerryleemelton1860
    @jerryleemelton1860 2 ปีที่แล้ว

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

  • @Onomandah
    @Onomandah 3 ปีที่แล้ว

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

  • @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.

  • @leoMC4384
    @leoMC4384 ปีที่แล้ว

    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. 👏👏👏

  • @abdianrizkyramadan1535
    @abdianrizkyramadan1535 3 ปีที่แล้ว +2

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

  • @NNNedlog
    @NNNedlog 3 ปีที่แล้ว

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

  • @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

  • @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.

  • @t4vex2
    @t4vex2 7 หลายเดือนก่อน

    congrats man, what a tutorial

  • @GiancarloCarccamo
    @GiancarloCarccamo 4 ปีที่แล้ว +3

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

  • @ZANES-YT
    @ZANES-YT 3 ปีที่แล้ว +1

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

  • @galipruz1690
    @galipruz1690 2 ปีที่แล้ว

    amazing man! thank you!

  • @xuanhuynh5952
    @xuanhuynh5952 3 ปีที่แล้ว

    It's awesome. Thank you Ed.

  • @fzrahmadan
    @fzrahmadan 2 ปีที่แล้ว

    thanks man, i really appreciate it!

  • @jennamaegabriel
    @jennamaegabriel 3 ปีที่แล้ว +2

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

  • @samueltorres2485
    @samueltorres2485 3 ปีที่แล้ว

    This was helpful, thanks!

  • @tawongachauluntha2880
    @tawongachauluntha2880 2 ปีที่แล้ว

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

  • @user-lc7rf4hg5v
    @user-lc7rf4hg5v 3 ปีที่แล้ว +1

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

  • @ferdinadcusihuamanayma2692
    @ferdinadcusihuamanayma2692 3 ปีที่แล้ว

    thank you for your totorials!

  • @CheMansur
    @CheMansur 5 ปีที่แล้ว

    Helped alot, thanks :D

  • @felipefonseca9281
    @felipefonseca9281 3 ปีที่แล้ว

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

  • @thegoat23452
    @thegoat23452 4 ปีที่แล้ว

    Thanks Dev Ed for all

  • @RameenFallschirmjager
    @RameenFallschirmjager 5 ปีที่แล้ว +5

    you code butter smooth bro!

  • @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.

  • @santiagoventura3211
    @santiagoventura3211 3 ปีที่แล้ว

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

  • @muhammadabdelbari9128
    @muhammadabdelbari9128 2 ปีที่แล้ว

    absolutely helpful thanks a lot

  • @heirsofchrist
    @heirsofchrist 4 ปีที่แล้ว

    Big Bro, it really helped. Thanks.

  • @mojr6874
    @mojr6874 4 ปีที่แล้ว

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

  • @mohamedelkashef7771
    @mohamedelkashef7771 3 ปีที่แล้ว

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

  • @epizarro309
    @epizarro309 3 ปีที่แล้ว

    Great video!

  • @evanilsonp.8183
    @evanilsonp.8183 ปีที่แล้ว

    Amazing!

  • @coolguy9616
    @coolguy9616 2 ปีที่แล้ว

    Hey man you are the best

  • @GGanzolo
    @GGanzolo 2 ปีที่แล้ว

    Thanks so much!

  • @lisofsky8151
    @lisofsky8151 3 ปีที่แล้ว

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

  • @issaissifou3579
    @issaissifou3579 4 ปีที่แล้ว

    Thank you so much!

  • @damendiaye3440
    @damendiaye3440 3 ปีที่แล้ว

    Thank you so simple so undestandable good job teacher

  • @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.

  • @Telugupuranalu
    @Telugupuranalu 2 ปีที่แล้ว

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

  • @sadstar7520
    @sadstar7520 2 ปีที่แล้ว

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

  • @denciosantos5316
    @denciosantos5316 3 ปีที่แล้ว

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

  • @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

  • @JustinPaulGT
    @JustinPaulGT 2 ปีที่แล้ว

    Thank you bro 💓

  • @fabricekarekezi9403
    @fabricekarekezi9403 4 ปีที่แล้ว

    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?

  • @mugambo5505
    @mugambo5505 2 ปีที่แล้ว

    Great vedio

  • @haobamjameskumar3962
    @haobamjameskumar3962 3 ปีที่แล้ว

    Best teacher ever

  • @stefaniaalbornozibanez3322
    @stefaniaalbornozibanez3322 3 ปีที่แล้ว

    gracias capo te agradezco muchisimo

  • @andrewkamoha4666
    @andrewkamoha4666 ปีที่แล้ว

    Would the tag simplify this tutorial?

  • @callmequeen17
    @callmequeen17 3 ปีที่แล้ว +1

    the papa bless made my heart happy c:

  • @tyassusanto9858
    @tyassusanto9858 2 ปีที่แล้ว

    thankyou very much sir

  • @dexterdragons
    @dexterdragons 4 ปีที่แล้ว

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

  • @f450fpv7
    @f450fpv7 หลายเดือนก่อน

    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.

  • @shubhambhatt329
    @shubhambhatt329 2 ปีที่แล้ว

    thank u bro becz of i make this model

  • @sovereignlivingsoul
    @sovereignlivingsoul 4 ปีที่แล้ว

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

  • @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

  • @ansariarbaz3374
    @ansariarbaz3374 3 ปีที่แล้ว

    IT IS AWESOME

  • @vishwajeetraj11
    @vishwajeetraj11 4 ปีที่แล้ว

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

  • @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';
    }
    }

  • @raulsantandertirado4400
    @raulsantandertirado4400 4 ปีที่แล้ว +1

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

  • @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

  • @deivi3697
    @deivi3697 2 ปีที่แล้ว

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

  • @richestboy_uz
    @richestboy_uz 3 ปีที่แล้ว

    👍👍👍👍

  • @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

  • @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?

  • @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.

  • @dilemma9865
    @dilemma9865 2 ปีที่แล้ว

    ❤❤

  • @aishikaroy6484
    @aishikaroy6484 3 ปีที่แล้ว

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

  • @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 2 ปีที่แล้ว

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

  • @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 😑😶😐

  • @priyankanispro
    @priyankanispro 2 ปีที่แล้ว +4

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

    • @deivi3697
      @deivi3697 2 ปีที่แล้ว +1

      Thankl you

  • @urmilaroy2747
    @urmilaroy2747 3 ปีที่แล้ว

    Please tell theme you used for this video

  • @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.

  • @vartikadehalvi5664
    @vartikadehalvi5664 3 ปีที่แล้ว

    how do we do it with gsap?

  • @MrsLalaina
    @MrsLalaina 2 ปีที่แล้ว

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

  • @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

  • @dominicvolante1616
    @dominicvolante1616 3 ปีที่แล้ว

    This is the easiest Modal I've ever seen

  • @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!!!!!!!!

  • @HK-sw3vi
    @HK-sw3vi 3 ปีที่แล้ว

    les fucking gooooooooooooo!

  • @ninadparkar6998
    @ninadparkar6998 3 ปีที่แล้ว

    How to make modal unscrollable?

  • @joelgeleta2266
    @joelgeleta2266 3 ปีที่แล้ว

    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 3 ปีที่แล้ว +2

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

  • @damolaadigun9574
    @damolaadigun9574 4 ปีที่แล้ว

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

  • @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

  • @sakshigoyal9018
    @sakshigoyal9018 3 ปีที่แล้ว

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

  • @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.

  • @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 ปีที่แล้ว

      th-cam.com/video/8A6mqAu4llg/w-d-xo.html
      this video has source code with explanation

  • @antoniosalzano5253
    @antoniosalzano5253 3 ปีที่แล้ว +1

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

  • @jojok.mikaka6955
    @jojok.mikaka6955 3 ปีที่แล้ว

    please ! show us the start of css code !

  • @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 ปีที่แล้ว

      th-cam.com/video/8A6mqAu4llg/w-d-xo.html
      this video has source code with explanation

  • @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.

  • @rohitkk1982
    @rohitkk1982 2 ปีที่แล้ว

    Can you share the code

  • @hesyashidiq1153
    @hesyashidiq1153 3 ปีที่แล้ว

    thanks (^_^)/

  • @STXplague
    @STXplague 3 ปีที่แล้ว

    Source code?

  • @ishaanpandey
    @ishaanpandey 3 ปีที่แล้ว +1

    did not work for me 😭😭😭😭

  • @sigmiami
    @sigmiami 4 ปีที่แล้ว +7

    Didnt work

  • @aliguliyev2122
    @aliguliyev2122 4 ปีที่แล้ว

    Could you send me a source code please :)