Okuva ku kanvaasi
Zimba sidebars ezikwekebwa mu pulojekiti yo okusobola okutambulira, ebigaali by'okugula, n'ebirala n'ebibiina ebitonotono ne JavaScript plugin yaffe.
Engeri gye kikola
Offcanvas kitundu kya sidebar ekiyinza okukyusibwa okuyita mu JavaScript okulabika okuva ku kkono, ku ddyo, waggulu, oba wansi ku bbali w'ekifo eky'okulaba. Buttons oba anchors zikozesebwa nga triggers eziyungibwa ku elements ebitongole by’okyusakyusa, era data
attributes zikozesebwa okuyita JavaScript yaffe.
- Offcanvas egabana ebimu ku koodi ya JavaScript y’emu ne modals. Mu ndowooza, zifaanagana nnyo, naye nga zibeera plugins ezenjawulo.
- Mu ngeri y’emu, enkyukakyuka ezimu ez’ensibuko Sass ez’emisono n’ebipimo bya offcanvas zisikira okuva mu nkyukakyuka za modal.
- Bwe kiragibwa, offcanvas erimu ekifaananyi ekisookerwako ekiyinza okunyigibwa okukweka offcanvas.
- Okufaananako ne modals, offcanvas emu yokka esobola okulagibwa omulundi gumu.
Emitwe gigulumivu! Kubanga CSS gy'ekwatamu ebifaananyi ebirina obulamu, tosobola kukozesa margin
oba translate
ku .offcanvas
elementi. Wabula, kozesa ekibiina nga ekintu ekyetongodde eky’okuzinga.
prefers-reduced-motion
kubuuza kw'emikutu. Laba ekitundu
ky'ekiteeso ekikendeezeddwa mu biwandiiko byaffe eby'okutuuka ku bantu .
Eby’okulabirako
Ebitundu ebitali bya kanvaasi
Wansi waliwo ekyokulabirako kya offcanvas ekiragiddwa nga bwe kibadde (via .show
on .offcanvas
). Offcanvas erimu okuwagira omutwe nga guliko button y'okuggalawo n'ekibiina ky'omubiri eky'okwesalirawo ku bimu ebisookerwako padding
. Tukuwa amagezi nti oteekemu emitwe egy'ebweru wa kanvaasi n'ebikolwa eby'okugoba buli lwe kiba kisoboka, oba okuwa ekikolwa eky'okugoba eky'olwatu.
Okuva ku kanvaasi
<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>
Live demo
Kozesa obutambi wansi okulaga n’okukweka ekintu ekitali kya kanvaasi ng’oyita mu JavaScript ekyusa .show
kiraasi ku kintu ne .offcanvas
kiraasi.
.offcanvas
akweka ebirimu (ebisookerwako) ..offcanvas.show
eraga ebirimu
Osobola okukozesa enkolagana n'ekintu href
, oba bbaatuuni eriko data-bs-target
ekintu. Mu mbeera zombi, the data-bs-toggle="offcanvas"
is required.
Okuva ku kanvaasi
<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>
Okuyiringisibwa kw’omubiri
Okutambula <body>
elementi kulemesebwa nga offcanvas ne backdrop yaayo birabika. Kozesa data-bs-scroll
ekintu okusobozesa <body>
okutambula.
Offcanvas nga eriko omubiri oguyiringisibwa
Gezaako okutambula ku lupapula olusigaddeyo okulaba eky’okulonda kino nga kikola.
<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>
Okutambula kw’omubiri n’okudda emabega
Osobola n’okusobozesa <body>
okutambula ng’olina ekifaananyi ekirabika.
Backdrop nga eriko okuzingulula
Gezaako okutambula ku lupapula olusigaddeyo okulaba eky’okulonda kino nga kikola.
<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>
Ekifo ekitali kikyukakyuka (static backdrop).
Backdrop bweteekebwa ku static, offcanvas tejja kuggalawo nga onyiga ebweru waayo.
Okuva ku kanvaasi
<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>
Offcanvas enzirugavu
Yayongerwako mu v5.2.0Kyusa endabika ya offcanvases ne utilities okusobola okuzikwataganya obulungi ku contexts ezenjawulo nga dark navbars. Wano twongerako .text-bg-dark
ku .offcanvas
ne .btn-close-white
ku okusobola .btn-close
okukola sitayiro entuufu ng’olina offcanvas enzirugavu. Bw’oba olina ebikka munda, lowooza ku ky’okwongera .dropdown-menu-dark
ku .dropdown-menu
.
Okuva ku kanvaasi
Teeka wano ebirimu ebitali ku kanvaasi.
<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>
Okuddamu
Yayongerwako mu v5.2.0Responsive offcanvas classes zikweka ebirimu ebweru w'ekifo eky'okulaba okuva mu breakpoint eragiddwa ne wansi. Waggulu w’ekifo ekyo eky’okumenya, ebirimu munda bijja kweyisa nga bulijjo. Okugeza, .offcanvas-lg
ekweka ebirimu mu offcanvas wansi w'ekifo lg
eky'okumenya, naye eraga ebirimu waggulu w'ekifo lg
eky'okumenya.
Okuddamu offcanvas
Kino kirimu ebiri munda mu .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>
Responsive offcanvas classes ziriwo emitala ku buli breakpoint.
.offcanvas
.offcanvas-sm
.offcanvas-md
.offcanvas-lg
.offcanvas-xl
.offcanvas-xxl
Okuteekebwa mu kifo
Tewali kuteekebwa kwa kusooka kwa bitundu bya offcanvas, kale olina okwongerako ekimu ku bika by'ebikyusa wansi.
.offcanvas-start
eteeka offcanvas ku kkono w'ekifo eky'okulaba (ekiragiddwa waggulu).offcanvas-end
ateeka offcanvas ku ddyo w'ekifo eky'okulaba.offcanvas-top
ateeka offcanvas waggulu ku viewport.offcanvas-bottom
ateeka offcanvas wansi ku viewport
Gezaako ebyokulabirako eby’okungulu, ku ddyo, ne wansi wansi.
Offcanvas waggulu
<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>
Offcanvas ku ddyo
<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>
Offcanvas wansi
<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>
Okutuuka ku bantu
Okuva ekipande ekitali kya kanvaasi mu ndowooza bwe kiri eky’okukubaganya ebirowoozo eky’engeri, kakasa nti ogattako aria-labelledby="..."
—okujuliza omutwe ogutali gwa kanvaasi —ku .offcanvas
. Weetegereze nti teweetaaga kwongerako role="dialog"
okuva lwe twayongerako dda nga tuyita mu JavaScript.
CSS
Enkyukakyuka ezikyukakyuka
Yayongerwako mu v5.2.0Nga ekitundu ku nkola ya Bootstrap egenda ekulaakulana enkyukakyuka za CSS, offcanvas kati ekozesa enkyukakyuka za CSS ez'omu kitundu ku .offcanvas
for enhanced real-time customization. Emiwendo gy'enkyukakyuka za CSS giteekebwawo nga giyita mu Sass, kale okulongoosa Sass kukyawagirwa, nakyo.
--#{$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};
Enkyukakyuka za 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;
Enkozesa
Plugin ya offcanvas ekozesa kiraasi ntono n'ebintu okukwata okusitula ebizito:
.offcanvas
akweka ebirimu.offcanvas.show
eraga ebirimu.offcanvas-start
akweka offcanvas ku kkono.offcanvas-end
akweka offcanvas ku ddyo.offcanvas-top
akweka offcanvas waggulu.offcanvas-bottom
akweka offcanvas wansi
Okwongerako bbaatuuni y'okugoba n'ekintu data-bs-dismiss="offcanvas"
, ekivaako enkola ya JavaScript. Kakasa nti okozesa <button>
elementi nayo okusobola okweyisa obulungi mu byuma byonna.
Okuyita mu bikwata ku data
Okukyusakyusa
Okwongerako data-bs-toggle="offcanvas"
ne a data-bs-target
oba href
ku elementi okugaba otomatika okufuga elementi emu offcanvas. Ekintu data-bs-target
kikkiriza ekisunsula CSS okukozesa offcanvas ku. Kakasa nti ogattako kiraasi offcanvas
ku elementi ya offcanvas. Bw'oba oyagala kiggule nga kisookerwako, yongera ku kiraasi ey'okugattako show
.
Okusiibula
Okugoba kuyinza okutuukirira n'ekintu ekiri data
ku bbaatuuni munda mu offcanvas nga bwe kiragibwa wansi:
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
oba ku button ebweru wa offcanvas nga okozesa data-bs-target
nga bwekiragibwa wansi:
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#my-offcanvas" aria-label="Close"></button>
Okuyita mu JavaScript
Ssobozesa mu ngalo ne:
const offcanvasElementList = document.querySelectorAll('.offcanvas')
const offcanvasList = [...offcanvasElementList].map(offcanvasEl => new bootstrap.Offcanvas(offcanvasEl))
Eby’okulondako
Nga eby'okulonda bwe bisobola okuyisibwa nga biyita mu bikwata ku data oba JavaScript, osobola okugattako erinnya ly'okulonda ku data-bs-
, nga mu data-bs-animation="{value}"
. Kakasa nti okyusa ekika kya case eky’erinnya ly’okulonda okuva ku “ camelCase ” okudda ku “ kebab-case ” ng’oyisa eby’okulonda ng’oyita mu data attributes. Okugeza, kozesa data-bs-custom-class="beautifier"
mu kifo kya data-bs-customClass="beautifier"
.
Okuva ku Bootstrap 5.2.0, ebitundu byonna biwagira ekintu kya data ekiterekeddwa eky'okugezesadata-bs-config
ekiyinza okuteeka ensengeka y'ebitundu ennyangu ng'olunyiriri lwa JSON. Ekintu bwe kiba data-bs-config='{"delay":0, "title":123}'
n'ebintu data-bs-title="456"
, omuwendo ogusembayo title
gujja kuba 456
era ebifaananyi bya data eby'enjawulo bijja kusazaamu emiwendo egyaweebwa ku data-bs-config
. Okugatta ku ekyo, ebikwata ku data ebiriwo bisobola okuteeka emiwendo gya JSON nga data-bs-delay='{"show":0,"hide":150}'
.
Erinnya | Okuwandiika | Okukosamu | Okunnyonnyola |
---|---|---|---|
backdrop |
boolean oba olunyiriristatic |
true |
Siiga backdrop ku mubiri nga offcanvas eggule. Ekirala, lambika static ku backdrop etaggalawo offcanvas nga onyigiddwa. |
keyboard |
boolean | true |
Eggalawo offcanvas nga escape key enyigiddwa. |
scroll |
boolean | false |
Kiriza omubiri okutambula nga offcanvas eggule. |
Enkola
Enkola ezitakwatagana n’enkyukakyuka
Enkola zonna eza API tezikwatagana era zitandika enkyukakyuka . Zidda eri oyo akubye amangu ddala ng'enkyukakyuka etandise naye nga tennaggwaako . Okugatta ku ekyo, okuyita enkola ku kitundu ekikyukakyuka kujja kubuusibwa amaaso .
Laba ebiwandiiko byaffe ebya JavaScript okumanya ebisingawo .
Ekola ebirimu byo nga ekintu ekitali ku kanvaasi. Akkiriza eby'okulonda eby'okwesalirawo object
.
Osobola okukola ekifaananyi ekitali kya kanvaasi n'omuzimbi, okugeza:
const bsOffcanvas = new bootstrap.Offcanvas('#myOffcanvas')
Engeri | Okunnyonnyola |
---|---|
getInstance |
Enkola ya static ekusobozesa okufuna offcanvas instance ekwatagana ne DOM element. |
getOrCreateInstance |
Enkola ya static ekusobozesa okufuna offcanvas instance ekwatagana ne DOM element, oba okukola empya singa teyali etandikibwawo. |
hide |
Ekweka ekintu ekitali kya kanvaasi. Edda eri omuyita nga ekintu ekitali kya kanvaasi tekinnakwekebwa ddala (kwe kugamba nga hidden.bs.offcanvas ekintu tekinnabaawo). |
show |
Alaga ekintu ekitali kya kanvaasi. Edda eri omuyita nga elementi ya offcanvas tennalagibwa ddala (kwe kugamba nga shown.bs.offcanvas ekintu tekinnabaawo). |
toggle |
Ekyusa ekintu ekitali ku kanvaasi okulaga oba okukwekebwa. Edda eri omuyita nga ekintu ekitali kya kanvaasi tekinnalagibwa oba okukwekebwa ddala (kwe kugamba nga shown.bs.offcanvas oba hidden.bs.offcanvas ekintu tekinnabaawo). |
Ebibaddewo
Bootstrap's offcanvas class eraga ebitonotono ebibaawo olw'okukwata mu nkola ya offcanvas.
Ekika ky’ekintu ekibaawo | Okunnyonnyola |
---|---|
hide.bs.offcanvas |
Ekintu kino kikubwa amangu ddala hide ng’enkola eyitiddwa. |
hidden.bs.offcanvas |
Ekintu kino kikubwa nga ekintu ekitali kya kanvaasi kikwekeddwa okuva eri omukozesa (kijja kulinda enkyukakyuka za CSS okuggwa). |
hidePrevented.bs.offcanvas |
Ekintu kino kikubwa nga offcanvas eragiddwa, backdrop yaayo eri static era okunyiga ebweru wa offcanvas kukolebwa. Ekintu era kikubwa nga ekisumuluzo ky'okutoloka kinywezeddwa era keyboard eky'okulonda ne kiteekebwa ku false . |
show.bs.offcanvas |
Ekintu kino kikuba amangu ddala nga show enkola ya instance eyitiddwa. |
shown.bs.offcanvas |
Ekintu kino kikubwa nga ekintu ekitali kya kanvaasi kikoleddwa okulabika eri omukozesa (kijja kulinda enkyukakyuka za CSS okuggwa). |
const myOffcanvas = document.getElementById('myOffcanvas')
myOffcanvas.addEventListener('hidden.bs.offcanvas', event => {
// do something...
})