Gwiritsani ntchito pulogalamu yowonjezera ya JavaScript ya Bootstrap kuti muwonjezere zokambirana patsamba lanu la mabokosi opepuka, zidziwitso za ogwiritsa ntchito, kapena zomwe mumakonda.
Momwe zimagwirira ntchito
Musanayambe ndi gawo la Bootstrap, onetsetsani kuti mwawerenga zotsatirazi popeza zosankha zathu zasintha posachedwa.
Ma modals amapangidwa ndi HTML, CSS, ndi JavaScript. Iwo ali pamwamba pa china chirichonse mu chikalatacho ndi kuchotsa mpukutu <body>kuti modal zolembedwa mipukutu m'malo.
Chifukwa cha momwe HTML5 imafotokozera semantics yake, mawonekedwe a autofocusHTML alibe mphamvu mu ma modals a Bootstrap. Kuti mukwaniritse zomwezo, gwiritsani ntchito JavaScript yokhazikika:
Pitilizani kuwerenga ma demo ndi malangizo ogwiritsira ntchito.
Zitsanzo
Zigawo za modal
Pansipa pali static modal chitsanzo (kutanthauza zake positionndipo displayzasinthidwa). Kuphatikizidwa ndi mutu wa modal, thupi la modal (lofunikira padding) ndi modal footer (posankha). Tikukupemphani kuti muphatikizepo mitu yamutu yokhala ndi zochita zochotsa ngati kuli kotheka, kapena muperekepo kanthu kena kochotsa.
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.
Chokhazikika pakati
Onjezani .modal-dialog-centeredku .modal-dialogmolunjika pakati pa modali.
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.
Tooltips ndi popovers
Zida ndi popovers zitha kuyikidwa m'ma modal ngati pakufunika . Ma modals akatsekedwa, zida zilizonse ndi ma popovers mkati mwake amachotsedwanso.
Gwiritsani ntchito gridi ya Bootstrap mkati mwa modal pomanga zisa .container-fluidmkati mwa .modal-body. Kenako, gwiritsani ntchito makalasi amtundu wa grid monga momwe mungachitire kwina kulikonse.
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
Mitundu yosiyanasiyana ya modal
Muli ndi mabatani angapo omwe onse amayambitsa modali yofanana ndi zomwe zili zosiyana pang'ono? Gwiritsani ntchito event.relatedTargetndi mawonekedwe a HTMLdata-* (mwina kudzera pa jQuery ) kuti musinthe zomwe zili mu modal kutengera batani lomwe ladina.
Pansipa pali chiwonetsero chamoyo chotsatiridwa ndi chitsanzo cha HTML ndi JavaScript. Kuti mumve zambiri, werengani zolemba zamodal zochitika kuti mumve zambiri 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>
Chotsani makanema ojambula
Kwa ma mods omwe amangowoneka m'malo mozimiririka kuti awoneke, chotsani .fadekalasiyo pazolemba zanu.
Matali amphamvu
Ngati kutalika kwa modal kumasintha pamene ili lotseguka, muyenera kuyimba $('#myModal').modal('handleUpdate')kuti mukonzenso malo a modal ngati scrollbar ikuwoneka.
Kufikika
Onetsetsani kuti muwonjezere role="dialog"ndi aria-labelledby="...", kutanthauza mutu wa modal, ku .modal, ndi role="document"pawokha .modal-dialog. Kuphatikiza apo, mutha kufotokoza za dialog yanu ya modal ndi aria-describedbypa .modal.
Kuyika makanema a YouTube
Kuyika makanema a YouTube mu ma modals kumafuna JavaScript yowonjezera osati mu Bootstrap kuti asiye kusewera ndi zina zambiri. Onani positi yothandiza ya Stack Overflow kuti mumve zambiri.
Zosankha zazikulu
Ma Modals ali ndi makulidwe awiri osankha, omwe amapezeka kudzera pamagulu osintha kuti ayikidwe pa .modal-dialog. Kukula uku kumayambira pazipata zina kuti mupewe zopingasa zopingasa pamawonekedwe ocheperako.
Large modal
...
Small modal
...
Kugwiritsa ntchito
Pulogalamu yowonjezera ya modal imasintha zinthu zanu zobisika mukafuna, kudzera pa data kapena JavaScript. Imawonjezeranso .modal-openkusokoneza machitidwe <body>opukutira osasintha ndikupanga a .modal-backdropkuti apereke malo odina kuti muchotse ma modal owonetsedwa mukadina kunja kwa modal.
Njira zonse za API ndizosasinthika ndipo zimayamba kusintha . Amabwerera kwa woyimbirayo atangoyamba kusintha koma asanathe . Kuonjezera apo, kuyitana kwa njira pa gawo losintha kudzanyalanyazidwa .
Sinthani pamanja malo a modal ngati kutalika kwa modali kukusintha pamene ili lotseguka (mwachitsanzo, ngati mpukutu utawonekera).
.modal('dispose')
Imawononga modal ya chinthu.
Zochitika
Kalasi ya modal ya Bootstrap imawulula zochitika zingapo kuti zigwirizane ndi machitidwe a modal. Zochitika zonse za modal zimachotsedwa pa modal yokha (ie pa <div class="modal">).
Mtundu wa Chochitika
Kufotokozera
show.bs.modal
Chochitika ichi chimayaka nthawi yomweyo shownjira yachitsanzo itayitanidwa. Ngati chifukwa cha kudina, chinthu chomwe chadina chimapezeka ngati relatedTargetkatundu wa chochitikacho.
zowonetsedwa.bs.modal
Chochitikachi chimachotsedwa pamene modal yawonetsedwa kwa wogwiritsa ntchito (idzadikirira kuti kusintha kwa CSS kumalize). Ngati chifukwa cha kudina, chinthu chodina chimapezeka ngati relatedTargetkatundu wa chochitikacho.