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, luna, a i ʻole ka ʻaoʻao lalo o ka ʻaoʻao ʻ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 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>
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" 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>
Owili kino
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 e hiki ai i ka holo ʻana <body>
.
Offcanvas me ka ʻōwili kino
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>
<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>
ʻO ka ʻōwili kino a me ke kua
Hiki iā ʻoe ke ʻae i ka <body>
ʻōwili ʻana me ke kua i ʻike ʻia.
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="#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>
Kāpae kūmau
Ke hoʻonoho ʻia ke kua i ka static, ʻaʻole e pani ka offcanvas ke kaomi ʻana ma waho.
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>
Kāpena ʻeleʻele
Hoʻohui ʻia ma v5.2.0E hoʻololi i ke ʻano o nā offcanvases me nā pono hana e hoʻokūkū maikaʻi iā lākou i nā pōʻaiapili like ʻole e like me nā navbar ʻeleʻele. Eia mākou e hoʻohui .text-bg-dark
ai i ka .offcanvas
a me .btn-close-white
ka .btn-close
no ke kāhiko kūpono me kahi kāwele ʻeleʻele. Inā loaʻa iā ʻoe nā hāʻule i loko, e noʻonoʻo e hoʻohui .dropdown-menu-dark
i .dropdown-menu
.
Offcanvas
E kau i ka maʻiʻo offcanvas ma ʻaneʻi.
<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>
Pane
Hoʻohui ʻia ma v5.2.0Hūnā nā papa offcanvas pane i ka ʻike ma waho o ke awa ʻike mai kahi haʻi a i lalo. Ma luna aʻe o kēlā haʻihaʻi, e hana nā mea i loko e like me ka mea maʻamau. No ka laʻana, .offcanvas-lg
hūnā ʻia ka ʻike ma kahi canvas ma lalo o ka lg
haʻihaʻi, akā e hōʻike ana i ka ʻike ma luna o ka lg
haʻihaʻi.
Pane offcanvas
He ʻike kēia i loko o kahi .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>
Loaʻa nā papa offcanvas pane no kēlā me kēia breakpoint.
.offcanvas
.offcanvas-sm
.offcanvas-md
.offcanvas-lg
.offcanvas-xl
.offcanvas-xxl
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 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 ʻā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 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>
ʻ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" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body small">
...
</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.
CSS
Nā mea hoʻololi
Hoʻohui ʻia ma v5.2.0Ma ke ʻano o ka hoʻololi ʻana o nā ʻano hoʻololi CSS o Bootstrap, hoʻohana ʻo offcanvas i nā ʻano CSS kūloko no ka hoʻomaikaʻi ʻana i ka manawa .offcanvas
maoli. Hoʻonohonoho ʻia nā waiwai no nā ʻano CSS ma o Sass, no laila ke kākoʻo mau ʻia nei ka hana maʻamau Sass.
--#{$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};
Nā hoʻololi 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;
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-top
huna i ka offcanvas ma luna.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 ke ʻano 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 kahi 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:
const offcanvasElementList = document.querySelectorAll('.offcanvas')
const offcanvasList = [...offcanvasElementList].map(offcanvasEl => new bootstrap.Offcanvas(offcanvasEl))
Nā koho
Hiki ke hāʻawi ʻia nā koho ma o nā ʻikepili a i ʻole JavaScript, hiki iā ʻoe ke hoʻohui i kahi inoa koho i data-bs-
, e like me ka data-bs-animation="{value}"
. E hōʻoia e hoʻololi i ke ʻano hihia o ka inoa koho mai " CamelCase " i " kebab-case " i ka wā e hāʻawi ai i nā koho ma o nā ʻano ʻikepili. No ka laʻana, hoʻohana data-bs-custom-class="beautifier"
ma kahi o data-bs-customClass="beautifier"
.
E like me Bootstrap 5.2.0, kākoʻo nā ʻāpana āpau i kahi hiʻohiʻona ʻikepili i mālama ʻiadata-bs-config
i hiki ke mālama i ka hoʻonohonoho ʻāpana maʻalahi ma ke ʻano he kaula JSON. Ke loaʻa nā ʻano mea data-bs-config='{"delay":0, "title":123}'
a me data-bs-title="456"
nā ʻano, ʻo ka title
waiwai hope loa 456
a na nā ʻano ʻikepili kaʻawale e kāpae i nā waiwai i hāʻawi ʻia ma data-bs-config
. Eia kekahi, hiki i nā ʻikepili ʻikepili ke hoʻopaʻa i nā waiwai JSON e like me data-bs-delay='{"show":0,"hide":150}'
.
inoa | ʻAno | Default | wehewehe |
---|---|---|---|
backdrop |
boolean a i ʻole ke kaulastatic |
true |
E hoʻopili i kahi kāʻei kua ma ke kino i ka wā e wehe ana ka offcanvas. ʻO kahi ʻē aʻe, e kuhikuhi static i kahi kāʻei kua pani ʻole i ka offcanvas ke kaomi ʻia. |
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 mea 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:
const bsOffcanvas = new bootstrap.Offcanvas('#myOffcanvas')
Kaʻina hana | wehewehe |
---|---|
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 i kahi mea DOM, a i ʻole hana i kahi mea hou inā ʻaʻole i hoʻomaka ʻia. |
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). |
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). |
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 ka hanana shown.bs.offcanvas a i ʻole).hidden.bs.offcanvas |
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 |
---|---|
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 mea offcanvas mai ka mea hoʻohana (e kali no ka hoʻololi ʻana o CSS). |
hidePrevented.bs.offcanvas |
Hoʻopau ʻia kēia hanana i ka wā e hōʻike ʻia ai ka offcanvas, kona kua a hoʻokō static ʻia kahi kaomi ma waho o ka offcanvas. Hoʻopau ʻia ka hanana i ke kaomi ʻana i ke kī pakele a hoʻonohonoho ʻia ke keyboard koho i false . |
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 ʻāpana offcanvas e ka mea hoʻohana (e kali no ka hoʻopau ʻana o CSS). |
const myOffcanvas = document.getElementById('myOffcanvas')
myOffcanvas.addEventListener('hidden.bs.offcanvas', event => {
// do something...
})