E hoʻohana i kā Bootstrap JavaScript modal plugin e hoʻohui i nā kamaʻilio i kāu pūnaewele no nā pahu kukui, nā hoʻolaha mea hoʻohana, a i ʻole nā mea maʻamau.
Pehea e hana ai
Ma mua o ka hoʻomaka ʻana me ka ʻāpana modal o Bootstrap, e ʻoluʻolu e heluhelu i kēia aʻe no ka mea ua loli hou kā mākou koho papa inoa.
Kūkulu ʻia nā ʻano me HTML, CSS, a me JavaScript. Hoʻonoho ʻia lākou ma luna o nā mea ʻē aʻe o ka palapala a wehe i ka ʻōwili mai ka <body>mea i ʻōwili ʻia nā ʻike modal.
Ke kaomi 'ana i ka modal "backdrop" e pani 'akomi i ka modal.
Kākoʻo ʻo Bootstrap i hoʻokahi puka aniani modal i ka manawa. ʻAʻole kākoʻo ʻia nā modal nested no ka mea ke manaʻoʻiʻo nei mākou he mau mea hoʻohana maikaʻi ʻole.
Hoʻohana ʻia nā modals position: fixed, hiki i kekahi manawa ke ʻano kikoʻī e pili ana i kāna hana. I nā manawa a pau e hiki ai, e kau i kāu HTML modal ma kahi kūlana kiʻekiʻe e pale aku i ka hoʻopilikia ʻana mai nā mea ʻē aʻe. Loaʻa paha ʻoe i nā pilikia i ka wā e hoʻopaʻa ʻia ai i .modalloko o kahi mea paʻa ʻē aʻe.
Ma muli o ka wehewehe ʻana o HTML5 i kāna mau semantics, ʻaʻohe hopena o ka ʻano autofocusHTML i nā modals Bootstrap. No ka loaʻa ʻana o ka hopena like, e hoʻohana i kekahi JavaScript maʻamau:
E hoʻomau i ka heluhelu no nā demos a me nā alakaʻi hoʻohana.
Nā laʻana
Nā mea waiwai
Aia ma lalo kahi laʻana modal staticposition (ʻo ia hoʻi ʻo ia a displayua hoʻopau ʻia). Hoʻokomo ʻia ke poʻomanaʻo modal, kino kino (pono no padding), a me ka footer modal (koho). Ke noi aku nei mākou iā ʻoe e hoʻokomo i nā poʻomanaʻo modal me nā hana hoʻokuʻu i ka wā hiki, a i ʻole e hāʻawi i kahi hana hoʻokuʻu ʻē aʻe.
Poʻo inoa
Hele ka kikokikona kino ma aneʻi.
Demo ola
E hoʻololi i kahi demo modal hana ma ke kaomi ʻana i ke pihi ma lalo. E paheʻe ia i lalo a mae mai ka piko o ka ʻaoʻao.
Modal title
Woohoo, you're reading this text in a modal!
ʻOka maʻiʻo lōʻihi
Ke lilo nā modals i lōʻihi no ka nānā ʻana o ka mea hoʻohana a i ʻole ka mea hoʻohana, ʻōwili kūʻokoʻa lākou mai ka ʻaoʻao ponoʻī. E ho'āʻo i ka demo ma lalo nei e ʻike i kā mākou manaʻo.
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.
Kūwaena kū pololei
Hoʻohui .modal-dialog-centeredi .modal-dialogke kikowaena kū pololei i ka 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.
Nā mea hana a me nā popovers
Hiki ke waiho ʻia nā mea hana a me nā popovers i loko o nā modals e like me ka mea e pono ai . Ke pani ʻia nā modals, hoʻokuʻu ʻia nā mea hana a me nā popovers i loko.
E hoʻohana i ka ʻōnaehana mākia Bootstrap i loko o kahi modal ma ka hoʻomoe ʻana .container-fluidi loko o ka .modal-body. A laila, e hoʻohana i nā papa ʻōnaehana maʻamau e like me kāu e hana ai ma nā wahi ʻē aʻe.
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
Ke hoʻololi nei i ka ʻike
Loaʻa i kahi pūʻulu o nā pihi e hoʻoulu ai i ke ʻano like me nā mea ʻokoʻa iki? E hoʻohana event.relatedTargeta me nā ʻano HTMLdata-* ( ma o jQuery paha ) e hoʻololi i nā ʻike o ka modal ma muli o ke pihi i kaomi ʻia.
Aia ma lalo kahi demo ola i ukali ʻia e ka HTML a me JavaScript. No ka ʻike hou aku, e heluhelu i nā moʻolelo hanana hanana no nā kikoʻī ma relatedTarget.
New message
Wehe i ka animation
No nā mods i ʻike wale ʻia ma mua o ka nalo ʻana e nānā, e wehe i ka .fadepapa mai kāu markup modal.
Nā kiʻekiʻe kiʻekiʻe
Inā hoʻololi ke kiʻekiʻe o kahi modal i ka wā e wehe ʻia ai, pono ʻoe e kelepona $('#myModal').modal('handleUpdate')e hoʻoponopono hou i ke kūlana o ka modal inā ʻike ʻia kahi scrollbar.
Hiki ke komo
E ʻoluʻolu e hoʻohui role="dialog"a aria-labelledby="...", e kuhikuhi ana i ke poʻo inoa modal, iā .modal, a role="document"iā .modal-dialogia iho. Eia hou, hiki iā ʻoe ke hāʻawi i kahi wehewehe o kāu kamaʻilio modal me aria-describedbyon .modal.
Hoʻokomo i nā wikiō YouTube
ʻO ka hoʻokomo ʻana i nā wikiō YouTube ma nā modals e pono ai ka JavaScript hou ʻaʻole i Bootstrap e hoʻōki maʻalahi i ka pāʻani a ʻoi aku. E ʻike i kēia pou Stack Overflow kōkua no ka ʻike hou aku.
Nā nui koho
Loaʻa i nā ʻano nui ʻelua koho, loaʻa ma o nā papa hoʻololi e kau ʻia ma kahi .modal-dialog. Hoʻokomo ʻia kēia mau nui i kekahi mau wahi haʻihaʻi e pale aku i nā scrollbar ākea ma nā wahi ʻike haiki.
Large modal
...
Small modal
...
Hoʻohana
Hoʻololi ka mod plugin i kāu ʻike huna ma ke koi, ma o nā hiʻohiʻona ʻikepili a i ʻole JavaScript. Hoʻohui pū ia .modal-openi ka <body>e override default scrolling behavior a hana i kahi .modal-backdrope hāʻawi i kahi kaomi no ka hoʻokuʻu ʻana i nā modals i hōʻike ʻia ke kaomi ʻana ma waho o ka modal.
Ma o nā hiʻohiʻona ʻikepili
E ho'ā i kahi modal me ke kākau ʻole i ka JavaScript. Hoʻonoho ʻia data-toggle="modal"ma kahi mea hoʻoponopono, e like me ke pihi, me kahi data-target="#foo"a href="#foo"i ʻole e kuhikuhi i kahi ʻano kikoʻī e hoʻololi.
Ma o JavaScript
Kāhea i kahi modal me ka id myModalme kahi laina o JavaScript:
Nā koho
Hiki ke hāʻawi ʻia nā koho ma o nā ʻikepili a i ʻole JavaScript. No nā ʻano ʻikepili, e hoʻopili i ka inoa koho i data-, e like me ka data-backdrop="".
inoa
ʻAno
Default
wehewehe
kāʻei kua
boolean a i ʻole ke kaula'static'
ʻoiaʻiʻo
Loaʻa i kahi ʻāpana modal-backdrop. ʻO kahi ʻē aʻe, e kuhikuhi statici kahi backdrop ʻaʻole i pani i ka modal ma ke kaomi.
keyboard
boolean
ʻoiaʻiʻo
Pani i ka modal ke kaomi ʻia ke kī pakele
kālele
boolean
ʻoiaʻiʻo
Kau i ka manaʻo i ka modal i ka wā i hoʻomaka ai.
hōʻike
boolean
ʻoiaʻiʻo
Hōʻike i ka modal i ka wā i hoʻomaka ai.
Nā ʻano hana
Nā ʻano asynchronous a me nā hoʻololi
Asynchronous nā ala API āpau a hoʻomaka i kahi hoʻololi . Hoʻi lākou i ka mea kelepona i ka wā e hoʻomaka ai ka hoʻololi akā ma mua o ka pau ʻana . Eia kekahi, e nānā ʻole ʻia kahi ala e kāhea ai i kahi mea hoʻololi .
Ho'ā i kāu ʻike ma ke ʻano he modal. ʻAe i kahi koho koho object.
.modal('toggle')
Hoʻololi lima i kahi ʻano. E hoʻi i ka mea kelepona ma mua o ka hōʻike ʻia ʻana a i ʻole huna ʻia ka modal (ʻo ia hoʻi ma mua o ka hiki ʻana o ka hanana shown.bs.modala i ʻole).hidden.bs.modal
.modal('show')
Wehe lima ʻia kahi modal. E hoʻi i ka mea kelepona ma mua o ka hōʻike ʻia ʻana o ka modal (ʻo ia hoʻi ma mua o ka hiki ʻana o ka shown.bs.modalhanana).
.modal('hide')
Hūnā lima ʻia kahi ʻano. E hoʻi i ka mea kelepona ma mua o ka hūnā ʻia ʻana o ka modal (ʻo ia hoʻi ma mua o ka hiki ʻana o ka hidden.bs.modalhanana).
.modal('handleUpdate')
Hoʻoponopono lima lima i ke kūlana o ke ʻano inā hoʻololi ke kiʻekiʻe o ke ʻano i ka wā e wehe ʻia ana (ʻo ia hoʻi, inā ʻike ʻia kahi scrollbar).
.modal('dispose')
Hoʻopau i ke ʻano o kekahi mea.
Nā hanana
Hōʻike ka papa modal Bootstrap i kekahi mau hanana no ka hoʻopili ʻana i ka hana modal. Hoʻopau ʻia nā hanana modal āpau ma ka modal ponoʻī (ʻo ia ma ka <div class="modal">).
ʻAno Hanana
wehewehe
hōʻike.bs.modal
Hoʻomaka koke kēia hanana i ke showkāhea ʻia ʻana o ke ʻano hana. Inā hoʻokumu ʻia e kahi kaomi, loaʻa ka mea kaomi ma ke ʻano he relatedTargetwaiwai o ka hanana.
hōʻike.bs.modal
Hoʻopau ʻia kēia hanana ke ʻike ʻia ka modal e ka mea hoʻohana (e kali no ka hoʻololi ʻana o CSS). Inā hoʻokumu ʻia e kahi kaomi, loaʻa ka mea kaomi ma ke ʻano he relatedTargetwaiwai o ka hanana.
huna.bs.modal
Hoʻopau koke ʻia kēia hanana i ka wā hidei kāhea ʻia ai ke ʻano hana.
huna.bs.modal
Hoʻopau ʻia kēia hanana i ka pau ʻana o ka huna ʻana o ka modal mai ka mea hoʻohana (e kali no ka hoʻololi ʻana o CSS).