Tirhisa Bootstrap’s JavaScript modal plugin ku engetela ti-dialog eka sayiti ya wena ku kuma mabokisi ya ku vonakala, switiviso swa vatirhisi, kumbe swilo leswi endleriweke wena hi ku helela.
Ndlela leyi swi tirhaka ha yona
Loko u nga si sungula hi xiphemu xa modal xa Bootstrap, tiyiseka leswaku u hlaya leswi landzelaka tanihi leswi swihlawulekisi swa hina swa menyu swi cinceke sweswinyana.
Timodali ti akiwile hi HTML, CSS na JavaScript. Va vekiwile ehenhla ka swin’wana hinkwaswo eka tsalwa naswona va susa ku rhendzeleka eka <body>leswaku nhundzu ya modal yi rhendzeleka ematshan’weni ya sweswo.
Ku tsindziyela eka “backdrop” ya modal swi ta pfala modal hi ku tisungulela.
Bootstrap yi seketela ntsena fasitere rin’we ra modal hi nkarhi. Ti modals leti nested a ti seketeriwi tanihileswi hi pfumelaka leswaku i mintokoto yo biha ya vatirhisi.
Modals use position: fixed, leyi minkarhi yin’wana yi nga va yo hlawuleka nyana hi ku hundzuluxela ka yona. Loko swi koteka, veka HTML ya wena ya modal eka xiyimo xa le henhla ku papalata ku kavanyeteka loku nga vaka kona ku suka eka swiaki swin’wana. U ta hlangana na swiphiqo loko u nesting a .modalendzeni ka element yin’wana leyi nga cinciki.
Nakambe, hikwalaho ka position: fixed, ku na switsundzuxo swo karhi hi ku tirhisa ti-modal eka switirhisiwa swa tiselfoni. Vona ti-doc ta hina ta nseketelo wa browser ku kuma vuxokoxoko.
Hikwalaho ka ndlela leyi HTML5 yi hlamuselaka semantiki ya yona ha yona, xihlawulekisi xa autofocusHTML a xi na vuyelo eka timodali ta Bootstrap. Leswaku u fikelela vuyelo lebyi fanaka, tirhisa JavaScript yin’wana leyi endleriweke wena:
Tshama u ri karhi u hlaya ku kuma ti-demo ni swiletelo swa matirhiselo.
Swikombiso
Swiphemu swa modal
Laha hansi ku na xikombiso xa static modal (leswi vulaka leswaku xa xona positionnaswona displayswi hungutiwile). Ku katsiwile nhloko ya modal, miri wa modal (lowu lavekaka eka padding), na nhloko ya modal (ya ku hlawula). Hi kombela leswaku u katsa tinhlokomhaka ta modal leti nga na swiendlo swo hlongola loko swi koteka, kumbe u nyika goza rin’wana ro hlongola leri nga erivaleni.
Xihloko xa Modal
Modal body text yi ya laha.
Demo leyi hanyaka
Cinca demo ya modal leyi tirhaka hi ku tikhoma buti leyi nga laha hansi. Yi ta rhetela ehansi yi tlhela yi nyamalala ku suka ehenhla ka tluka.
Modal title
Woohoo, you're reading this text in a modal!
Ku rhendzeleka ka swilo swo leha
Loko ti modals ti leha ngopfu eka viewport kumbe xitirhisiwa xa mutirhisi, ti scroll ti tiyimele hi toxe eka tluka hi roxe. Ringeta demo leyi nga laha hansi ku vona leswaku hi vula yini.
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.
Yi le xikarhi hi ndlela leyi yimisiweke
Engetela .modal-dialog-centeredeka .modal-dialogku vertically center ya 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.
Switsundzuxo swa switirhisiwa na ti-popovers
Ti Tooltips nati popovers tinga vekiwa endzeni ka ti modals tani hileswi swilaveka. Loko ti modals ti pfariwile, ti tootips tihi na tihi na ti popovers endzeni na tona ti hlongoriwa hi ku tisungulela.
Tirhisa sisiteme ya giridi ya Bootstrap endzeni ka modal hi ku endla swisaka .container-fluidendzeni ka .modal-body. Kutani, tirhisa titlilasi ta fambiselo ra gridi leti tolovelekeke hilaha u nga ta endla hakona kun’wana ni kun’wana.
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
Ku hambana ka swilo swa modal
Xana u na ntlhambi wa swikomba-nkarhi leswi hinkwaswo swi pfuxaka modal yin’we leyi nga ni swilo leswi hambaneke nyana? Tirhisa event.relatedTargetna swihlawulekisi swa HTMLdata-* (swi nga endleka hi ku tirhisa jQuery ) ku cinca-cinca leswi nga endzeni ka modal ku ya hi leswaku i buti yihi leyi tsindziyeleke.
Laha hansi ku na demo leyi hanyaka leyi landzeriwaka hi xikombiso xa HTML na JavaScript. Ku kuma vuxokoxoko byo tala, hlaya ti-doc ta swiendlakalo swa modal ku kuma vuxokoxoko eka relatedTarget.
New message
<buttontype="button"class="btn btn-primary"data-toggle="modal"data-target="#exampleModal"data-whatever="@mdo">Open modal for @mdo</button><buttontype="button"class="btn btn-primary"data-toggle="modal"data-target="#exampleModal"data-whatever="@fat">Open modal for @fat</button><buttontype="button"class="btn btn-primary"data-toggle="modal"data-target="#exampleModal"data-whatever="@getbootstrap">Open modal for @getbootstrap</button><divclass="modal fade"id="exampleModal"tabindex="-1"role="dialog"aria-labelledby="exampleModalLabel"aria-hidden="true"><divclass="modal-dialog"role="document"><divclass="modal-content"><divclass="modal-header"><h5class="modal-title"id="exampleModalLabel">New message</h5><buttontype="button"class="close"data-dismiss="modal"aria-label="Close"><spanaria-hidden="true">×</span></button></div><divclass="modal-body"><form><divclass="form-group"><labelfor="recipient-name"class="col-form-label">Recipient:</label><inputtype="text"class="form-control"id="recipient-name"></div><divclass="form-group"><labelfor="message-text"class="col-form-label">Message:</label><textareaclass="form-control"id="message-text"></textarea></div></form></div><divclass="modal-footer"><buttontype="button"class="btn btn-secondary"data-dismiss="modal">Close</button><buttontype="button"class="btn btn-primary">Send message</button></div></div></div></div>
Susa swifaniso leswi hanyaka
Eka ti-modal leti humelelaka ntsena ematshan’weni yo nyamalala leswaku ti ta languta, susa .fadetlilasi eka mfungho wa wena wa modal.
Ku tlakuka loku cinca-cincaka
Loko ku tlakuka ka modal ku cinca loko yi pfulekile, u fanele ku bela riqingho $('#myModal').modal('handleUpdate')leswaku u lulamisa xiyimo xa modal loko ko tshuka ku humelela scrollbar.
Ku fikelela
Tiyiseka leswaku u engetela role="dialog"na aria-labelledby="...", u kombetela eka xihloko xa modal, eka .modal, na role="document"le ka .modal-dialogxona hi xoxe. Ku engetela kwalaho, u nga ha nyika nhlamuselo ya mbulavurisano wa wena wa modal hi aria-describedbyon .modal.
Ku nghenisa tivhidiyo ta YouTube
Ku nghenisa tivhidiyo ta YouTube eka ti-modal swi lava JavaScript leyi engetelekeke leyi nga riki eka Bootstrap leswaku yi yimisa ku tlanga hi ku tisungulela ni swin’wana. Vona post leyi ya Stack Overflow leyi pfunaka ku kuma vuxokoxoko byo tala.
Tisayizi leti nga hlawuriwa
Timodali ti na tisayizi timbirhi to hlawula, leti kumekaka hi ku tirhisa titlilasi ta mucinci leti nga ta vekiwa eka .modal-dialog. Tisayizi leti ti nghena eka tindhawu to karhi to tshoveka leswaku ti papalata ti- scrollbar leti nga etlhelo eka swivono leswitsongo.
Large modal
...
Small modal
...
Matirhiselo
Plugin ya modal yi cinca-cinca swilo swa wena leswi fihliweke loko swi laviwa, hi ku tirhisa swihlawulekisi swa data kumbe JavaScript. Yi tlhela yi engetela .modal-openeka <body>ku tlula mahanyelo ya ku rhendzeleka ka xiviri naswona yi humesa a .modal-backdropku nyika ndhawu yo tsindziyela yo hlongola timodali leti kombisiweke loko u tsindziyela ehandle ka modali.
Hi ku tirhisa swihlawulekisi swa data
Endla leswaku modal yi tirha handle ko tsala JavaScript. Seta data-toggle="modal"eka elemente ya controller, ku fana na button, xikan’we na a data-target="#foo"kumbe href="#foo"ku kongomisa modal yo karhi ku toggle.
Hi ku tirhisa JavaScript
Fonela modal hi id myModalhi layini yin’we ya JavaScript:
Swihlawulekisi
Swihlawulekisi swi nga hundzisiwa hi ku tirhisa swihlawulekisi swa data kumbe JavaScript. Eka swihlawulekisi swa datha, engetela vito ra xihlawuhlawu eka data-, tanihi le ka data-backdrop="".
Vito
Muxaka
Ku tlula
Nhlamuselo
xifaniso xa le ndzhaku
boolean kumbe ntambhu'static'
ntiyiso
Ku katsa na xiaki xa modal-backdrop. Handle ka sweswo, boxa staticeka backdrop leyi nga pfaliki modal eka click.
xikhiya xa xikhiya
xitsonga xitsonga
ntiyiso
Ku pfala modal loko ku tshikileriwa escape key
kongoma
xitsonga xitsonga
ntiyiso
Yi veka ku kongomisa eka modal loko yi sunguriwa.
kombisa
xitsonga xitsonga
ntiyiso
Ku kombisa modal loko yi sunguriwa.
Maendlelo
Maendlelo ya asynchronous na ku cinca
Maendlelo hinkwawo ya API i ya asynchronous naswona ya sungula ku cinca . Va tlhelela eka mufoyini hi ku hatlisa loko ku cinca ku sungurile kambe ku nga si hela . Ku engetela kwalaho, ku vitaniwa ka ndlela eka xiphemu lexi cincaka ku ta honisiwa .
Ku endla leswaku nhundzu ya wena yi tirha tanihi modal. Ku amukela swihlawulekisi swa ku hlawula object.
.modal('toggle')
Hi voko u cinca-cinca modal. Ku tlhelela eka mufoyini loko modal yi nga si kombisiwa kumbe ku tumbetiwa hakunene (i.e. emahlweni ka ku humelela shown.bs.modalkumbe hidden.bs.modalxiendlakalo).
.modal('show')
Hi voko u pfula modal. Ku tlhelela eka mufoyini loko modal yi nga si kombisiwa hakunene (i.e. shown.bs.modalxiendlakalo xi nga si humelela).
.modal('hide')
Hi voko u tumbeta modal. Ku tlhelela eka mufoyini loko modal yi nga si fihliwa hakunene (i.e. hidden.bs.modalxiendlakalo xi nga si humelela).
.modal('handleUpdate')
Lulamisa hi voko xiyimo xa modal loko ku tlakuka ka modal ku cinca loko yi pfulekile (i.e. loko ku humelela scrollbar).
.modal('dispose')
Ku herisa modal ya elemente.
Swiendlakalo
Tlilasi ya modal ya Bootstrap yi paluxa swiendlakalo swi nga ri swingani swo khoma eka ntirho wa modal. Swiendlakalo hinkwaswo swa modal swi duvuriwa eka modal hi yoxe (i.e. eka <div class="modal">).
Muxaka wa Xiendlakalo
Nhlamuselo
kombisa.bs.modal
Xiendlakalo lexi xi pfurha hi ku hatlisa loko ku showvitaniwa ndlela ya xikombiso. Loko swi vangiwa hi ku tsindziyela, xiaki lexi tsindziyeleke xi kumeka tanihi relatedTargetnhundzu ya xiendlakalo.
ku kombisiwile.bs.modal
Xiendlakalo lexi xi duvuriwa loko modal yi endliwile yi vonaka eka mutirhisi (yi ta rindza ku cinca ka CSS ku hela). Loko swi vangiwa hi ku tsindziyela, xiaki lexi tsindziyeleke xi kumeka tanihi relatedTargetnhundzu ya xiendlakalo.
fihla.bs.modal
Xiendlakalo lexi xi duvuriwa hi ku hatlisa loko ndlela ya hidexikombiso yi vitaniwile.
leswi fihliweke.bs.modal
Xiendlakalo lexi xi duvuriwa loko modal yi hetile ku tumbetiwa eka mutirhisi (yi ta rindza ku cinca ka CSS ku hela).