I-offcanvas
Yakha amabha aseceleni afihliwe kuphrojekthi yakho yokuzulazula, izinqola zokuthenga, nokuningi ngamakilasi ambalwa kanye ne-plugin yethu ye-JavaScript.
Isebenza kanjani
I-Offcanvas ingxenye yebha eseceleni engashintshwa nge-JavaScript ukuze ivele kwesokunxele, kwesokudla, phezulu, noma kunqenqema olungezansi lwembobo yokubuka. Izinkinobho noma amahange asetshenziswa njengezibangeli ezinamathiselwe kuzinto ezithile ozishintshayo, futhi data
izibaluli zisetshenziselwa ukunxenxa i-JavaScript yethu.
- I-Offcanvas yabelana ngekhodi ye-JavaScript efanayo njengamamodali. Ngokomqondo, ziyefana, kodwa zingama-plugin ahlukene.
- Ngokufanayo, umthombo othile oguquguqukayo we-Sass wezitayela nobukhulu be-offcanvas buzuzwa njengefa kusukela kokuguquguqukayo kwe-modal.
- Uma kuboniswa, i-offcanvas ihlanganisa okwasemuva okuzenzakalelayo okungachofozwa ukuze kufihlwe i-offcanvas.
- Ngokufana namamodeli, kungaboniswa i-offcanvas eyodwa kuphela ngesikhathi.
Amakhanda phezulu! Uma kunikezwe ukuthi i-CSS iphatha kanjani ukugqwayiza, awukwazi ukusebenzisa margin
noma translate
ku- .offcanvas
elementi. Kunalokho, sebenzisa ikilasi njengento yokugoqa ezimele.
prefers-reduced-motion
embuzweni wemidiya. Bona ingxenye
yokunyakaza encishisiwe yemibhalo yethu yokufinyeleleka .
Izibonelo
Izingxenye ze-offcanvas
Ngezansi kunesibonelo se-offcanvas esiboniswa ngokuzenzakalelayo (nge- .show
on .offcanvas
). I-offcanvas ihlanganisa ukusekelwa kwesihloko esinenkinobho yokuvala kanye nesigaba somzimba ozikhethela sona ekuqaleni okuthile padding
. Siphakamisa ukuthi ufake izihloko ze-offcanvas ngezenzo zokucashisa noma nini lapho kunokwenzeka, noma unikeze isenzo sokuchitha esisobala.
I-offcanvas
<div class="offcanvas offcanvas-start show" tabindex="-1" id="offcanvas" aria-labelledby="offcanvasLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasLabel">Offcanvas</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
Content for the offcanvas goes here. You can place just about any Bootstrap component or custom elements here.
</div>
</div>
Idemo ebukhoma
Sebenzisa izinkinobho ezingezansi ukuze ubonise futhi ufihle i-elementi ye-offcanvas usebenzisa i-JavaScript eguqula .show
ikilasi entweni .offcanvas
ngeklasi.
.offcanvas
ifihla okuqukethwe (okuzenzakalelayo).offcanvas.show
ikhombisa okuqukethwe
Ungasebenzisa isixhumanisi href
esinesibaluli, noma inkinobho data-bs-target
enesibaluli. Kuzo zombili izimo, data-bs-toggle="offcanvas"
kuyadingeka.
I-offcanvas
<a class="btn btn-primary" data-bs-toggle="offcanvas" href="#offcanvasExample" role="button" aria-controls="offcanvasExample">
Link with href
</a>
<button class="btn btn-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasExample" aria-controls="offcanvasExample">
Button with data-bs-target
</button>
<div class="offcanvas offcanvas-start" tabindex="-1" id="offcanvasExample" aria-labelledby="offcanvasExampleLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasExampleLabel">Offcanvas</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<div>
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.
</div>
<div class="dropdown mt-3">
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown">
Dropdown button
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</div>
</div>
</div>
Ukuskrola komzimba
Ukuskrola i- <body>
elementi kukhutshaziwe uma i-offcanvas nokwasemuva kwayo kubonakala. Sebenzisa data-bs-scroll
isibaluli ukuze unike amandla <body>
ukuskrola.
Ama-offcanvas anomzimba oskrola
Zama ukuskrola lonke ikhasi ukuze ubone le nketho isebenza.
<button class="btn btn-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasScrolling" aria-controls="offcanvasScrolling">Enable body scrolling</button>
<div class="offcanvas offcanvas-start" data-bs-scroll="true" data-bs-backdrop="false" tabindex="-1" id="offcanvasScrolling" aria-labelledby="offcanvasScrollingLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasScrollingLabel">Offcanvas with body scrolling</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<p>Try scrolling the rest of the page to see this option in action.</p>
</div>
</div>
Ukuskrola komzimba nokwasemuva
Ungakwazi futhi ukunika amandla <body>
ukuskrola ngengemuva elibonakalayo.
Ingemuva elinokuskrola
Zama ukuskrola lonke ikhasi ukuze ubone le nketho isebenza.
<button class="btn btn-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasWithBothOptions" aria-controls="offcanvasWithBothOptions">Enable both scrolling & backdrop</button>
<div class="offcanvas offcanvas-start" data-bs-scroll="true" tabindex="-1" id="offcanvasWithBothOptions" aria-labelledby="offcanvasWithBothOptionsLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasWithBothOptionsLabel">Backdrop with scrolling</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<p>Try scrolling the rest of the page to see this option in action.</p>
</div>
</div>
Ingemuva elimile
Uma okwasemuva kusethelwe ku-static, i-offcanvas ngeke ivaleke uma uchofozwa ngaphandle kwayo.
I-offcanvas
<button class="btn btn-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#staticBackdrop" aria-controls="staticBackdrop">
Toggle static offcanvas
</button>
<div class="offcanvas offcanvas-start" data-bs-backdrop="static" tabindex="-1" id="staticBackdrop" aria-labelledby="staticBackdropLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="staticBackdropLabel">Offcanvas</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<div>
I will not close if you click outside of me.
</div>
</div>
</div>
Ikhanvasi emnyama
Kwengezwe ku-v5.2.0Shintsha ukubukeka kwama-offcanvases ngezinsiza ukuze uwafanise kangcono nezimo ezihlukene njengama-navbar amnyama. Lapha sengeza .text-bg-dark
ku- .offcanvas
kanye .btn-close-white
nokwenza .btn-close
isitayela esifanele nge-offcanvas emnyama. Uma unokudonsela phansi ngaphakathi, cabanga nokungeza .dropdown-menu-dark
kokuthi .dropdown-menu
.
I-offcanvas
Beka okuqukethwe kwe-offcanvas lapha.
<div class="offcanvas offcanvas-start show text-bg-dark" tabindex="-1" id="offcanvasDark" aria-labelledby="offcanvasDarkLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasDarkLabel">Offcanvas</h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="offcanvasDark" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<p>Place offcanvas content here.</p>
</div>
</div>
Iyasabela
Kwengezwe ku-v5.2.0Amakilasi e-offcanvas aphendulayo afihla okuqukethwe ngaphandle kwembobo yokubuka kusukela endaweni ethile ecacisiwe naphansi. Ngaphezulu kwalelo phuzu, okuqukethwe ngaphakathi kuzoziphatha njengokujwayelekile. Isibonelo, .offcanvas-lg
ifihla okuqukethwe ku-offcanvas ngaphansi kwe- lg
breakpoint, kodwa ibonisa okuqukethwe ngaphezu kwe- lg
breakpoint.
I-offcanvas esabelayo
Lokhu okuqukethwe ngaphakathi kwe- .offcanvas-lg
.
<button class="btn btn-primary d-lg-none" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasResponsive" aria-controls="offcanvasResponsive">Toggle offcanvas</button>
<div class="alert alert-info d-none d-lg-block">Resize your browser to show the responsive offcanvas toggle.</div>
<div class="offcanvas-lg offcanvas-end" tabindex="-1" id="offcanvasResponsive" aria-labelledby="offcanvasResponsiveLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasResponsiveLabel">Responsive offcanvas</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#offcanvasResponsive" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<p class="mb-0">This is content within an <code>.offcanvas-lg</code>.</p>
</div>
</div>
Amakilasi e-offcanvas aphendulayo ayatholakala endaweni yokuphumula ngayinye.
.offcanvas
.offcanvas-sm
.offcanvas-md
.offcanvas-lg
.offcanvas-xl
.offcanvas-xxl
Ukubekwa
Akukho ukubekwa okuzenzakalelayo kwezingxenye ze-offcanvas, ngakho-ke kufanele wengeze iklasi elilodwa lesilungisi ngezansi.
.offcanvas-start
beka ikhanvasi kwesokunxele sembobo yokubuka (eboniswe ngenhla).offcanvas-end
ibeka amakhanvasi kwesokudla sembobo yokubuka.offcanvas-top
ibeka amakhanvasi phezulu kwendawo yokubuka.offcanvas-bottom
ibeka amakhanvasi phansi kwembobo yokubuka
Zama izibonelo ezingenhla, kwesokudla, nezingezansi ngezansi.
Okuphezulu kwe-offcanvas
<button class="btn btn-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasTop" aria-controls="offcanvasTop">Toggle top offcanvas</button>
<div class="offcanvas offcanvas-top" tabindex="-1" id="offcanvasTop" aria-labelledby="offcanvasTopLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasTopLabel">Offcanvas top</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
...
</div>
</div>
I-offcanvas kwesokudla
<button class="btn btn-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasRight" aria-controls="offcanvasRight">Toggle right offcanvas</button>
<div class="offcanvas offcanvas-end" tabindex="-1" id="offcanvasRight" aria-labelledby="offcanvasRightLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasRightLabel">Offcanvas right</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
...
</div>
</div>
Phansi kwekhanvasi
<button class="btn btn-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasBottom" aria-controls="offcanvasBottom">Toggle bottom offcanvas</button>
<div class="offcanvas offcanvas-bottom" tabindex="-1" id="offcanvasBottom" aria-labelledby="offcanvasBottomLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasBottomLabel">Offcanvas bottom</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body small">
...
</div>
</div>
Ukufinyeleleka
Njengoba iphaneli ye-offcanvas ngokomqondo iyingxoxo eyimodeli, qiniseka ukuthi uyengeza aria-labelledby="..."
—ubhekisela kusihloko se-offcanvas—ku- .offcanvas
. Qaphela ukuthi awudingi ukungeza role="dialog"
njengoba sesivele sengeze nge-JavaScript.
CSS
Okuguquguqukayo
Kwengezwe ku-v5.2.0Njengengxenye yendlela yokuguquguquka kwe-CSS ye-Bootstrap, i-offcanvas manje isebenzisa okuguquguqukayo kwasendaweni kwe-CSS .offcanvas
ukuze kwenziwe ngokwezifiso isikhathi sangempela esithuthukisiwe. Amanani okuguquguquka kwe-CSS asethwa nge-Sass, ngakho ukwenza ngokwezifiso kwe-Sass kusasekelwa, nakho.
--#{$prefix}offcanvas-zindex: #{$zindex-offcanvas};
--#{$prefix}offcanvas-width: #{$offcanvas-horizontal-width};
--#{$prefix}offcanvas-height: #{$offcanvas-vertical-height};
--#{$prefix}offcanvas-padding-x: #{$offcanvas-padding-x};
--#{$prefix}offcanvas-padding-y: #{$offcanvas-padding-y};
--#{$prefix}offcanvas-color: #{$offcanvas-color};
--#{$prefix}offcanvas-bg: #{$offcanvas-bg-color};
--#{$prefix}offcanvas-border-width: #{$offcanvas-border-width};
--#{$prefix}offcanvas-border-color: #{$offcanvas-border-color};
--#{$prefix}offcanvas-box-shadow: #{$offcanvas-box-shadow};
Izinguquko ze-Sass
$offcanvas-padding-y: $modal-inner-padding;
$offcanvas-padding-x: $modal-inner-padding;
$offcanvas-horizontal-width: 400px;
$offcanvas-vertical-height: 30vh;
$offcanvas-transition-duration: .3s;
$offcanvas-border-color: $modal-content-border-color;
$offcanvas-border-width: $modal-content-border-width;
$offcanvas-title-line-height: $modal-title-line-height;
$offcanvas-bg-color: $modal-content-bg;
$offcanvas-color: $modal-content-color;
$offcanvas-box-shadow: $modal-content-box-shadow-xs;
$offcanvas-backdrop-bg: $modal-backdrop-bg;
$offcanvas-backdrop-opacity: $modal-backdrop-opacity;
Ukusetshenziswa
I-plugin ye-offcanvas isebenzisa amakilasi ambalwa nezimfanelo ukuphatha ukuphakamisa okusindayo:
.offcanvas
ifihla okuqukethwe.offcanvas.show
ikhombisa okuqukethwe.offcanvas-start
ifihla i-offcanvas ngakwesobunxele.offcanvas-end
ifihla i-offcanvas ngakwesokudla.offcanvas-top
ifihla i-offcanvas phezulu.offcanvas-bottom
ifihla i-offcanvas phansi
Engeza inkinobho yokucashisa data-bs-dismiss="offcanvas"
ngesibaluli, esicupha ukusebenza kwe-JavaScript. Qiniseka ukuthi usebenzisa i- <button>
elementi nayo ngokuziphatha okufanele kuwo wonke amadivayisi.
Ngezibaluli zedatha
Guqula
Engeza data-bs-toggle="offcanvas"
kanye data-bs-target
noma href
ku-elementi ukuze unikeze ngokuzenzakalelayo ukulawula kwento eyodwa ye-offcanvas. Isibaluli data-bs-target
samukela isikhethi se-CSS ongafaka kuso i-offcanvas. Qiniseka ukuthi ungeza ikilasi offcanvas
kusici se-offcanvas. Uma ungathanda ukuthi ivuleke ngokuzenzakalelayo, engeza iklasi elengeziwe show
.
Cashisa
Ukuxoshwa kungafinyelelwa ngesibaluli esisenkinobho engaphakathi kwekhanvasidata
njengoba kuboniswe ngezansi:
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
noma enkinobho engaphandle kwekhanvasi usebenzisa lokhu data-bs-target
okuboniswe ngezansi:
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#my-offcanvas" aria-label="Close"></button>
Nge-JavaScript
Nika amandla ngokwenza nge:
const offcanvasElementList = document.querySelectorAll('.offcanvas')
const offcanvasList = [...offcanvasElementList].map(offcanvasEl => new bootstrap.Offcanvas(offcanvasEl))
Izinketho
Njengoba izinketho zingadluliswa ngezibaluli zedatha noma i-JavaScript, ungakwazi ukwengeza igama lenketho kokuthi data-bs-
, njengaku data-bs-animation="{value}"
. Qiniseka ukuthi ushintsha uhlobo lwekesi legama lenketho lisuka ku- “ camelCase ” liye ku- “ kebab-case ” lapho udlulisa izinketho ngezibaluli zedatha. Isibonelo, sebenzisa data-bs-custom-class="beautifier"
esikhundleni se- data-bs-customClass="beautifier"
.
Kusukela ku-Bootstrap 5.2.0, zonke izingxenye zisekela isibaluli sedatha egodliwe esihlolwayodata-bs-config
esingafaka ukucushwa kwengxenye elula njengochungechunge lwe-JSON. Uma into inezibaluli , inani lokugcina lizoba data-bs-config='{"delay":0, "title":123}'
futhi izibaluli zedatha ezihlukene zizokhipha amanani anikezwe ngomhla ka- . Ngaphezu kwalokho, izibaluli zedatha ezikhona ziyakwazi ukubeka amanani e-JSON afana .data-bs-title="456"
title
456
data-bs-config
data-bs-delay='{"show":0,"hide":150}'
Igama | Uhlobo | Okuzenzakalelayo | Incazelo |
---|---|---|---|
backdrop |
i-boolean noma intambostatic |
true |
Faka okwasemuva emzimbeni ngenkathi i-offcanvas ivuliwe. Okunye, cacisa static okwasemuva okungavali i-offcanvas uma ichofozwa. |
keyboard |
boolean | true |
Ivala i-offcanvas uma ukhiye we-escape ucindezelwa. |
scroll |
boolean | false |
Vumela ukuskrola komzimba ngenkathi i-offcanvas ivuliwe. |
Izindlela
Izindlela ze-Asynchronous kanye noshintsho
Zonke izindlela ze-API azivumelanisi futhi ziqala inguquko . Babuyele kofonayo uma sekuqalwa uguquko kodwa lungakapheli . Ngokungeziwe, ikholi yendlela engxenyeni yoshintsho izozitshwa .
Bheka imibhalo yethu ye-JavaScript ukuze uthole ulwazi olwengeziwe .
Yenza okuqukethwe kwakho kusebenze njengengxenye ye-offcanvas. Yamukela izinketho ozikhethela object
.
Ungakha isenzakalo se-offcanvas nomakhi, isibonelo:
const bsOffcanvas = new bootstrap.Offcanvas('#myOffcanvas')
Indlela | Incazelo |
---|---|
getInstance |
Indlela emile ekuvumela ukuthi uthole isenzakalo se- offcanvas esihlotshaniswa nento ye-DOM. |
getOrCreateInstance |
Indlela emile ekuvumela ukuthi uthole isenzakalo se- offcanvas esihlotshaniswa nento ye-DOM, noma udale entsha uma kwenzeka ingaqaliswanga. |
hide |
Ifihla isici se-offcanvas. Ibuyela kofonayo ngaphambi kokuba isici se-offcanvas sifihlwe (okungukuthi ngaphambi kokuthi hidden.bs.offcanvas kwenzeke umcimbi). |
show |
Ibonisa isici se-offcanvas. Ibuyela kofonayo ngaphambi kokuba kuboniswe isici se-offcanvas (okungukuthi ngaphambi kokuthi shown.bs.offcanvas kwenzeke umcimbi). |
toggle |
Iguqula into ye-offcanvas iboniswe noma ifihlwe. Ibuyela kofonayo ngaphambi kokuba isici se-offcanvas siboniswe noma sifihlwe (okungukuthi ngaphambi kokuthi kwenzeke shown.bs.offcanvas noma hidden.bs.offcanvas isigameko). |
Imicimbi
Ikilasi le-offcanvas le-Bootstrap lidalula imicimbi embalwa yokuxhunywa ekusebenzeni kwe-offcanvas.
Uhlobo lomcimbi | Incazelo |
---|---|
hide.bs.offcanvas |
Lo mcimbi uxoshwa ngokushesha lapho hide indlela isibiziwe. |
hidden.bs.offcanvas |
Lo mcimbi uxoshwa lapho isici se-offcanvas sifihliwe kumsebenzisi (sizolinda ukuthi izinguquko ze-CSS ziqedele). |
hidePrevented.bs.offcanvas |
Lo mcimbi uyaxoshwa uma i-offcanvas iboniswa, ingemuva layo likhona static futhi ukuchofoza ngaphandle kwe-offcanvas kwenziwa. Umcimbi uphinde ucishwe lapho ukhiye wokuphunyuka ucindezelwa futhi keyboard inketho isethwe ukuze false . |
show.bs.offcanvas |
Lo mcimbi uvutha ngokushesha lapho show indlela yesibonelo ibizwa. |
shown.bs.offcanvas |
Lo mcimbi uxoshwa lapho isici se-offcanvas senziwe sabonakala kumsebenzisi (sizolinda ukuthi izinguquko ze-CSS ziqedele). |
const myOffcanvas = document.getElementById('myOffcanvas')
myOffcanvas.addEventListener('hidden.bs.offcanvas', event => {
// do something...
})