Yuz Bootstrap in JavaSkript modal plɔgin fɔ ad dayalɔg dɛn to yu sayt fɔ laytbɔks, yuz notis, ɔ kɔmplit kɔstɔm kɔntinyu.
Aw i de wok
Bifo yu bigin wit Bootstrap in modal kɔmpɔnɛnt, mek shɔ se yu rid wetin de dɔŋ ya bikɔs wi mɛnyu opshɔn dɛn dɔn chenj i nɔ tu te yet.
Dɛn bil di mɔdal dɛn wit HTML, CSS, ɛn JavaSkript. Dɛn de posishun oba ɔl ɔda tin dɛn na di dɔkyumɛnt ɛn pul skrol frɔm di <body>so dat modal kɔntinyu skrol insted.
We yu klik di modal “bakdrop” i go lɔk di modal ɔtomɛtik wan.
Bootstrap de sɔpɔt wan modal winda nɔmɔ wan tɛm. Nested modals nɔ de sɔpɔt as wi biliv se dɛn na po yuz ɛkspiriɛns.
Modals use position: fixed, we kin sɔm tɛm dɛn kin bi smɔl patikyula bɔt in rɛnda. Ɛnitɛm we i pɔsibul, put yu modal HTML na wan tɔp-lɛvel pozishɔn fɔ avɔyd pɔtnɛshɛl intafɛreshɔn frɔm ɔda ɛlimɛnt dɛn. Yu go mɔs rɔn insay prɔblɛm dɛn we yu de nest wan .modalinsay ɔda fiks ɛlimɛnt.
Wans bak, bikɔs ɔf position: fixed, sɔm kɔvɛt dɛn de wit yuz modal dɛn na mobayl divays dɛn. Si wi brawza sɔpɔt dɔkyumɛnt dɛn fɔ di ditel dɛn.
Bikɔs ɔf aw HTML5 de difayn in sɛmantiks, di autofocusHTML atribyut nɔ gɛt ɛni ifɛkt na Bootstrap modals. Fɔ mek yu ebul fɔ du di sem tin, yuz sɔm kɔstɔm JavaSkript:
Kɔntinyu fɔ rid fɔ di demo ɛn aw fɔ yuz gaydlayn dɛn.
Ɛgzampul dɛn
Modal komponent dɛn
Dis dɔŋ ya na wan statik modal ɛgzampul (we min in positionɛn displaydɛn dɔn ɔvarayd). Insay de, di modal hεda, di modal bכdi (we nid fכ padding), εn di modal fut (opshכnal). Wi de aks yu fɔ put modal hεda wit dismis akshɔn ɛnitɛm we i pɔsibul, ɔ gi ɔda klia dismis akshɔn.
Modal taytul
Modal bodi teks go ya.
Layf dɛmo
Toggle wan wok modal demo bay we yu klik di bɔtin we de dɔŋ. I go slayv dɔŋ ɛn fade insay frɔm di ɔp pat na di pej.
Modal title
Woohoo, you're reading this text in a modal!
Skrol lɔng kɔntinyu
We di modal dɛn kin tu lɔng fɔ di pɔsin in viupɔt ɔ divays, dɛn kin skrol indipɛndɛnt frɔm di pej sɛf. Tray di demo we de dɔŋ fɔ si wetin wi min.
Modal title
Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.
Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.
Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.
Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.
Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.
Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.
Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.
Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.
Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.
Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.
Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.
Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.
Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.
Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.
Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.
Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.
Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.
Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.
Vertikal wan we de na di sɛnt
Add .modal-dialog-centeredto .modal-dialogfɔ vertikal sɛnt di modal.
Modal title
Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.
Tultips ɛn popovers
Tultips ɛn popovers kin put insay modals as nid de. We dɛn lɔk modal dɛn, ɛni tultip ɛn popovers insay dɛnsɛf kin ɔtomɛtik dismis.
Yutilayz di Bootstrap grid sistem insay wan modal bay we yu de nest .container-fluidinsay di .modal-body. Dɔn, yuz di nɔmal grid sistɛm klas dɛn lɛk aw yu go du ɛni ɔda say.
Grids in modals
.col-md-4
.col-md-4 .ml-auto
.col-md-3 .ml-auto
.col-md-2 .ml-auto
.col-md-6 .ml-auto
Level 1: .col-sm-9
Level 2: .col-8 .col-sm-6
Level 2: .col-4 .col-sm-6
Difrɛn difrɛn modal kɔntinyu
Yu gɛt wan bɔnch bɔtin dɛn we ɔl de trig di sem modal wit smɔl difrɛn kɔntinyu? Yuz event.relatedTargetɛn HTML data-*atribyut dɛn (i kin bi bay jQuery ) fɔ chenj di tin dɛn we de insay di modal dipen pan us bɔtin dɛn klik.
Dis dɔŋ ya na layv dɛmo we de fala wit ɛgzampul HTML ɛn JavaSkript. Fɔ no mɔ, rid di modal events docs fɔ di ditel dɛn bɔt relatedTarget.
New message
Rimov di animashɔn
Fɔ modal dɛn we jɔs de apia pas fɔ fade in fɔ si, pul di .fadeklas frɔm yu modal mak.
Dinamik ayt dɛn
If di ayt fɔ wan modal chenj we i opin, yu fɔ kɔl $('#myModal').modal('handleUpdate')fɔ ajɔst di modal in pozishɔn bak if wan skrolba apia.
Di we aw pɔsin kin ebul fɔ go de
Mek shɔ se yu ad role="dialog"ɛn aria-labelledby="...", we de rɛfrɛns di modal taytul, to .modal, ɛn role="document"to di .modal-dialogsɛf. Apat frɔm dat, yu kin gi diskripshɔn fɔ yu modal dayalɔg wit aria-describedbyon .modal.
Fɔ put di fim dɛn na Yutub fɔ put insay
Fɔ ɛmbas Yutub fim dɛn na modal dɛn nid fɔ gɛt ɔda JavaSkript we nɔ de na Bootstrap fɔ mek i stɔp fɔ ple ɔtomɛtik wan ɛn ɔda tin dɛn. Si dis ɛp Stack Overflow post fɔ mɔ infɔmeshɔn.
Saiz dɛn we yu kin pik
Modal dɛn gɛt tu opshɔnal saiz dɛn, we de bay modifya klas dɛn fɔ put pan wan .modal-dialog. Dɛn saiz dɛn ya kin kik insay sɔm brek pɔynt dɛn fɔ avɔyd ɔrizɔntal skrol bar dɛn na smɔl smɔl viupɔt dɛn.
Large modal
...
Small modal
...
Aw fɔ yuz am
Di modal plɔgin de chenj yu kɔntinyu we yu ayd we yu aks fɔ am, bay we yu yuz data atribyut ɔ JavaSkript. I de ad bak .modal-opento di <body>fɔ ɔvalayz difɔlt skrolin bihayvya ɛn jenarayz wan .modal-backdropfɔ gi wan klik eria fɔ dismis di modal dɛn we dɛn sho we yu klik ausayd di modal.
Via data atribyut dɛn
Aktiv wan modal we nɔ rayt JavaSkript. Sɛt data-toggle="modal"pan wan kɔntrol ɛlimɛnt, lɛk wan bɔtin, wit wan data-target="#foo"ɔ href="#foo"fɔ tɔch wan patikyula modal fɔ tɔgl.
Yu kin yuz JavaSkript fɔ yuz am
Kɔl wan modal wit id myModalwit wan layn na JavaSkript:
Di tin dɛn we yu kin pik fɔ du
Yu kin pas opshɔn dɛn bay we yu yuz data atribyut ɔ JavaSkript. Fɔ data atribyut dɛn, ad di opshɔn nem to data-, lɛk insay data-backdrop="".
Nem
Kayn
Balans
Tɔk bɔt
bakdrop fɔ de
boolean ɔ di string'static'
tru
Inklud wan modal-bakdrop ɛlimɛnt. Ɔda we de fɔ du dat, spɛsifa staticfɔ wan bakdrop we nɔ de lɔk di modal we yu klik.
kibɔd fɔ di kibɔd
boolean we dɛn kɔl
tru
Klos di modal we dɛn prɛs di ɛspɛk ki
tink bɔt
boolean we dɛn kɔl
tru
Put di fos pan di modal we dɛn initialize.
sho
boolean we dɛn kɔl
tru
Sho di modal we dɛn initialize.
Di we aw dɛn de du am
Asynchronous mεtכd dεm εn transishכn dεm
Ɔl di API mɛtɔd dɛn na asynchronous ɛn dɛn kin stat wan transishɔn . Dɛn kin go bak to di pɔsin we kɔl am jɔs lɛk aw dɛn bigin fɔ chenj bɔt bifo i dɔn . Apat frɔm dat, dɛn go ignore wan mɛtɔd kɔl pan wan transishɔn kɔmpɔnɛnt .
Aktiv yu kɔntinyu as modal. Aksept wan opshɔnal opshɔn dɛn object.
.modal('toggle')
Manually de toggle wan modal. Ritɔn to di pɔsin we kɔl bifo di modal dɔn rili sho ɔ ayd (dat na bifo di shown.bs.modalɔ hidden.bs.modalivin apin).
.modal('show')
Manually de opin wan modal. Ritɔn to di pɔsin we kɔl bifo di modal dɔn rili sho (dat na bifo di shown.bs.modalivin apin).
.modal('hide')
Manually de ayd wan modal. Ritɔn to di pɔsin we kɔl bifo di modal dɔn rili ayd (dat na bifo di hidden.bs.modalivin apin).
.modal('handleUpdate')
Riadjɔst di modal in pozishɔn wit yu an if di ayt fɔ wan modal chenj we i opin (dat na if wan skrolba apia).
.modal('dispose')
Destroy wan element in modal.
Di tin dɛn we kin apin
Bootstrap in modal klas de ɛksplɔz sɔm ivin dɛn fɔ huk insay modal funkshɔnaliti. Ɔl di modal ivin dɛn de faya na di modal sɛf (dat na na di <div class="modal">).
Di kayn tin we apin
Tɔk bɔt
sho.bs.modal fɔ sho
Dis ivent de faya wantɛm wantɛm we dɛn kɔl di showinstans mɛtɔd. If na klik, di ɛlimɛnt we dɛn klik de as di relatedTargetprɔpati fɔ di ivin.
we dɛn sho.bs.modal
Dis ivent de faya we di modal dɔn mek di pɔsin we de yuz am si (go wet fɔ mek di CSS transishɔn dɛn dɔn). If na klik, di ɛlimɛnt we dɛn klik de as di relatedTargetprɔpati fɔ di ivin.
ayd.bs.modal fɔ di wan dɛn we de
Dis ivent de faya wantɛm wantɛm we hidedɛn dɔn kɔl di instans mɛtɔd.
we dɛn ayd.bs.modal
Dis ivent de faya we di modal dɔn dɔn fɔ ayd frɔm di yuza (go wet fɔ CSS transishɔn dɛn fɔ dɔn).