Offcanvas
E kūkulu i nā ʻaoʻao ʻaoʻao huna i kāu papahana no ka hoʻokele, nā kaʻa kūʻai, a me nā mea hou aku me kekahi mau papa a me kā mākou plugin JavaScript.
Pehea e hana ai
He ʻāpana ʻaoʻao ʻaoʻao ʻo Offcanvas i hiki ke hoʻololi ʻia ma o JavaScript e ʻike ʻia mai ka ʻaoʻao hema, ʻākau, a i ʻole ka ʻaoʻao lalo o ka ʻike. Hoʻohana ʻia nā pihi a i ʻole nā heleuma e like me nā mea hoʻomaka i hoʻopili ʻia i nā mea kikoʻī āu e hoʻololi ai, a data
ua hoʻohana ʻia nā ʻano e kāhea i kā mākou JavaScript.
- Hāʻawi ʻo Offcanvas i kekahi o nā code JavaScript like me nā modals. ʻO ka manaʻo, ua like lākou, akā he mau plugins kaʻawale.
- Pēlā nō, hoʻoili ʻia kekahi kumu hoʻololi Sass no nā ʻano a me nā ana o offcanvas mai nā ʻano hoʻololi o ka modal.
- Ke hōʻike ʻia, loaʻa i ka offcanvas kahi kāʻei paʻamau i hiki ke kaomi e hūnā i ka offcanvas.
- E like me nā modals, hiki ke hōʻike ʻia hoʻokahi offcanvas i ka manawa.
Nā poʻo i luna! Hāʻawi ʻia pehea e mālama ai ʻo CSS i nā animation, ʻaʻole hiki iā ʻoe ke hoʻohana a i margin
ʻole translate
ma kahi .offcanvas
mea. Akā, e hoʻohana i ka papa ma ke ʻano he mea hoʻopili kūʻokoʻa.
prefers-reduced-motion
nīnau media. E ʻike
i ka ʻāpana hoʻohaʻahaʻa o kā mākou palapala hiki ke komo .
Nā laʻana
ʻO nā ʻāpana canvas
Aia ma lalo kahi hiʻohiʻona offcanvas i hōʻike ʻia ma ka paʻamau (ma .show
on .offcanvas
). Loaʻa i ka Offcanvas ke kākoʻo no kahi poʻomanaʻo me kahi pihi pili a me kahi papa kino koho no kekahi padding
. Manaʻo mākou e hoʻokomo i nā poʻomanaʻo offcanvas me nā hana hoʻokuʻu inā hiki, a i ʻole e hāʻawi i kahi hana hoʻokuʻu maopopo.
Offcanvas
<div class="offcanvas offcanvas-start" 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 text-reset" 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>
Demo ola
E hoʻohana i nā pihi ma lalo nei e hōʻike a hūnā i kahi ʻāpana offcanvas ma o JavaScript e hoʻololi i ka .show
papa ma kahi mea me ka .offcanvas
papa.
.offcanvas
huna maʻiʻo (paʻamau).offcanvas.show
hōʻike maʻiʻo
Hiki iā ʻoe ke hoʻohana i kahi loulou me ka href
ʻano, a i ʻole ke pihi me ka data-bs-target
ʻano. I nā hihia ʻelua, data-bs-toggle="offcanvas"
pono ka mea.
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 text-reset" 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" id="dropdownMenuButton" data-bs-toggle="dropdown">
Dropdown button
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<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>
Hoʻokomo
ʻAʻohe wahi paʻamau no nā ʻāpana offcanvas, no laila pono ʻoe e hoʻohui i kekahi o nā papa hoʻololi ma lalo;
.offcanvas-start
waiho i ka canvas ma ka hema o ke awa nana (e hoike ana maluna).offcanvas-end
kau i ka canvas ma ka ʻākau o ke awa nānā.offcanvas-top
kau i ka canvas ma luna o ke awa nānā.offcanvas-bottom
e waiho i ka canvas ma lalo o ka puka nānā
E ho'āʻo i nā hiʻohiʻona luna, ʻākau, a lalo ma lalo.
ʻO luna o waho
<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 id="offcanvasTopLabel">Offcanvas top</h5>
<button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
...
</div>
</div>
Offcanvas ʻākau
<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 id="offcanvasRightLabel">Offcanvas right</h5>
<button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
...
</div>
</div>
ʻO lalo o ka canvas
<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 text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body small">
...
</div>
</div>
Kāpae
Hoʻopau ʻia ka ʻōwili ʻana i ka <body>
element ke ʻike ʻia kahi offcanvas a me kona kua. E hoʻohana i ke data-bs-scroll
ʻano no ka hoʻololi ʻana i ka <body>
ʻōwili a me data-bs-backdrop
ka hoʻololi ʻana i ke kua.
Kāwili ʻia me ka ʻōwili
E hoʻāʻo e ʻōwili i ke koena o ka ʻaoʻao e ʻike i kēia koho i ka hana.
Offcanvas me ke kua
.....
Kāpae me ka ʻōwili
E hoʻāʻo e ʻōwili i ke koena o ka ʻaoʻao e ʻike i kēia koho i ka hana.
<button class="btn btn-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasScrolling" aria-controls="offcanvasScrolling">Enable body scrolling</button>
<button class="btn btn-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasWithBackdrop" aria-controls="offcanvasWithBackdrop">Enable backdrop (default)</button>
<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" data-bs-backdrop="false" tabindex="-1" id="offcanvasScrolling" aria-labelledby="offcanvasScrollingLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasScrollingLabel">Colored with scrolling</h5>
<button type="button" class="btn-close text-reset" 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>
<div class="offcanvas offcanvas-start" tabindex="-1" id="offcanvasWithBackdrop" aria-labelledby="offcanvasWithBackdropLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasWithBackdropLabel">Offcanvas with backdrop</h5>
<button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<p>.....</p>
</div>
</div>
<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 text-reset" 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>
Hiki ke komo
No ka mea he kamaʻilio kumu ka offcanvas panel, e hōʻoia e hoʻohui aria-labelledby="..."
—e kuhikuhi ana i ka inoa offcanvas—i .offcanvas
. E hoʻomaopopo ʻaʻole pono ʻoe e hoʻohui role="dialog"
no ka mea ua hoʻohui mākou iā ia ma o JavaScript.
Sass
Nā mea hoʻololi
$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;
Hoʻohana
Hoʻohana ka plugin offcanvas i kekahi mau papa a me nā hiʻohiʻona e hoʻokele i ka hāpai kaumaha:
.offcanvas
hūnā i ka ʻike.offcanvas.show
hōʻike i ka ʻike.offcanvas-start
huna i ka offcanvas ma ka hema.offcanvas-end
hūnā i ka offcanvas ma ka ʻākau.offcanvas-bottom
huna i ka offcanvas ma lalo
Hoʻohui i kahi pihi hoʻokuʻu me ke data-bs-dismiss="offcanvas"
ʻano, e hoʻoulu i ka hana JavaScript. E hoʻohana pono i ka <button>
mea me ia no ka hana kūpono ma nā ʻaoʻao āpau.
Ma o nā hiʻohiʻona ʻikepili
Hoʻololi
Hoʻohui data-bs-toggle="offcanvas"
a a i data-bs-target
ʻole href
i ka mea e hāʻawi ʻakomi i ka mana o hoʻokahi mea offcanvas. ʻAe ka ʻano i kahi mea koho CSS e hoʻopili i ka data-bs-target
offcanvas i. E ʻoluʻolu e hoʻohui i ka papa offcanvas
i ka mea offcanvas. Inā makemake ʻoe e wehe paʻamau, e hoʻohui i ka papa hou show
.
Hoʻokuʻu
Hiki ke hoʻokō ʻia ka hoʻokuʻu ʻana me ke ʻano data
ma kahi pihi i loko o ka offcanvas e like me ka hōʻike ʻana ma lalo nei:
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
a i ʻole ma ke pihi ma waho o ka canvas me ka hoʻohana ʻana i ka data-bs-target
mea i hōʻike ʻia ma lalo nei:
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#my-offcanvas" aria-label="Close"></button>
Ma o JavaScript
E ho'ā me ka lima me:
var offcanvasElementList = [].slice.call(document.querySelectorAll('.offcanvas'))
var offcanvasList = offcanvasElementList.map(function (offcanvasEl) {
return new bootstrap.Offcanvas(offcanvasEl)
})
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-bs-
, e like me ka data-bs-backdrop=""
.
inoa | ʻAno | Default | wehewehe |
---|---|---|---|
backdrop |
boolean | true |
E hoʻopili i kahi kāʻei kua ma ke kino i ka wā e wehe ana ka offcanvas |
keyboard |
boolean | true |
Pani i ka offcanvas ke paʻi ʻia ke kī pakele |
scroll |
boolean | false |
E ʻae i ka hele ʻana o ke kino i ka wā e wehe ana ka offcanvas |
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 ʻāpana offcanvas. ʻAe i kahi koho koho object
.
Hiki iā ʻoe ke hana i kahi laʻana offcanvas me ka mea hana, no ka laʻana:
var myOffcanvas = document.getElementById('myOffcanvas')
var bsOffcanvas = new bootstrap.Offcanvas(myOffcanvas)
ʻano hana | wehewehe |
---|---|
toggle |
Hoʻololi i kahi ʻāpana offcanvas i hōʻike ʻia a hūnā paha. E hoʻi i ka mea kelepona ma mua o ka hōʻike ʻia ʻana a i ʻole huna ʻia o ka offcanvas element (ʻo ia hoʻi ma mua o ka hiki ʻana o shown.bs.offcanvas ka hidden.bs.offcanvas hanana). |
show |
Hōʻike i kahi ʻāpana offcanvas. E hoʻi i ka mea kelepona ma mua o ka hōʻike ʻia ʻana o ka mea offcanvas (ʻo ia hoʻi ma mua o ka hiki ʻana o ka shown.bs.offcanvas hanana). |
hide |
Hūnā i kahi ʻeleʻele offcanvas. E hoʻi i ka mea kelepona ma mua o ka hūnā ʻia ʻana o ka mea offcanvas (ʻo ia hoʻi ma mua o ka hiki ʻana o ka hidden.bs.offcanvas hanana). |
getInstance |
ʻO ke ala static e hiki ai iā ʻoe ke kiʻi i ka laʻana offcanvas e pili ana me kahi mea DOM |
getOrCreateInstance |
ʻO ke ʻano static e hiki ai iā ʻoe ke kiʻi i ka laʻana offcanvas e pili ana me kahi mea DOM, a i ʻole hana i kahi mea hou inā ʻaʻole i hoʻomaka ʻia. |
Nā hanana
Hōʻike ka papa offcanvas o Bootstrap i kekahi mau hanana no ka hoʻopili ʻana i ka hana offcanvas.
ʻAno hanana | wehewehe |
---|---|
show.bs.offcanvas |
Hoʻomaka koke kēia hanana i ke show kāhea ʻia ʻana o ke ʻano hana. |
shown.bs.offcanvas |
Hoʻopau ʻia kēia hanana i ka wā i ʻike ʻia ai kahi mea offcanvas i ka mea hoʻohana (e kali no ka hoʻopau ʻana o CSS). |
hide.bs.offcanvas |
Hoʻopau koke ʻia kēia hanana ke hide kāhea ʻia ke ʻano. |
hidden.bs.offcanvas |
Hoʻopau ʻia kēia hanana i ka wā i hūnā ʻia ai kahi ʻāpana offcanvas mai ka mea hoʻohana (e kali no ka hoʻololi ʻana o CSS). |
var myOffcanvas = document.getElementById('myOffcanvas')
myOffcanvas.addEventListener('hidden.bs.offcanvas', function () {
// do something...
})