Offcanvas
Jiri klaasị ole na ole na ngwa mgbakwunye Javascript wulite akụkụ zoro ezo n'ime ọrụ gị maka ịnyagharị, ụgbọ ịzụ ahịa na ihe ndị ọzọ.
Ka o si arụ ọrụ
Offcanvas bụ akụkụ akụkụ nke enwere ike ịtụgharị site na Javascript ka ọ pụta n'akụkụ aka ekpe, aka nri, n'elu, ma ọ bụ ala ala nke ebe nlele. A na-eji bọtịnụ ma ọ bụ arịlịka dị ka ihe na-akpali akpali nke etinyere na ihe ụfọdụ ị na-atụgharị, yana data
njirimara a na-eji kpọkuo Javascript anyị.
- Offcanvas na-ekerịta ụfọdụ koodu Javascript dị ka modal. N'echiche, ha yiri nnọọ, mana ha bụ plugins dị iche iche.
- N'otu aka ahụ, a na-eketa ụfọdụ mgbanwe Sass maka ụdị na akụkụ nke offcanvas site na mgbanwe modal.
- Mgbe egosiri, offcanvas na-agụnye ndabere ndabere nke enwere ike ịpị iji zoo enyo ahụ.
- Yiri modal, ọ bụ naanị otu oyi akwa ka enwere ike igosi n'otu oge.
Welie isi elu! Nyere ka CSS si ejikwa animation, ị nweghị ike iji margin
ma ọ bụ translate
na .offcanvas
mmewere. Kama, jiri klaasị ahụ dị ka ihe mkpuchi nwere onwe.
prefers-reduced-motion
ajụjụ mgbasa ozi. Hụ akụkụ
ngagharị ewelatala nke akwụkwọ nnweta anyị .
Ihe atụ
Ngwa ndị dịpụrụ adịpụ
N'okpuru ebe a bụ ọmụmaatụ offcanvas nke egosiri na ndabara (site .show
na .offcanvas
). Offcanvas gụnyere nkwado maka nkụnye eji isi mee nke nwere bọtịnụ nso yana klaasị ahụ nhọrọ maka ụfọdụ mbido padding
. Anyị na-atụ aro ka ị tinye isi ihe ndị dịpụrụ adịpụ na omume ịchụpụ mgbe ọ bụla enwere ike, ma ọ bụ wepụta mmemme ịchụpụ nke ọma.
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>
Ihe ngosi dị ndụ
Jiri bọtịnụ dị n'okpuru ka igosi ma zoo ihe dịpụrụ adịpụ site na Javascript nke na-atụgharị .show
klaasị na mmewere ya na .offcanvas
klaasị.
.offcanvas
na-ezobe ọdịnaya (nke ndabara).offcanvas.show
na-egosi ọdịnaya
Ị nwere ike iji njikọ nwere href
njirimara, ma ọ bụ bọtịnụ nwere data-bs-target
àgwà ahụ. N'okwu abụọ a, data-bs-toggle="offcanvas"
achọrọ ya.
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>
Mpịakọta ahụ
Akwụsịghị ịpịgharị <body>
ihe ahụ mgbe a na-ahụ ihe dịpụrụ adịpụ na ebe ndabere ya. Jiri data-bs-scroll
njirimara iji mee ka <body>
ịpịgharịa.
Offcanvas nwere mpịakọta ahụ
Gbalịa ịpịgharịa na ibe ndị ọzọ ka ịhụ nhọrọ a na-arụ ọrụ.
<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>
Mpịakọta ahụ na azụ azụ
Ị nwekwara ike mee ka <body>
ịpịgharịa ya na ebe a na-ahụ anya.
Backdrop nwere mpịakọta
Gbalịa ịpịgharịa na ibe ndị ọzọ ka ịhụ nhọrọ a na-arụ ọrụ.
<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>
Ebe static
Mgbe atọrọ backdrop ka ọ dị static, offcanvas agaghị emechi mgbe ịpị na mpụga ya.
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>
Akara gbara ọchịchịrị
Agbakwunyere na v5.2.0Gbanwee ọdịdị nke offcanvases na akụrụngwa iji dabaa nke ọma na ọnọdụ dị iche iche dị ka ụgbọ mmiri gbara ọchịchịrị. N'ebe a, anyị na-agbakwunye .text-bg-dark
na .offcanvas
na .btn-close-white
maka .btn-close
nhazi nke ọma na akwa mkpuchi gbara ọchịchịrị. Ọ bụrụ na ị nwere ọdịda n'ime, tụlee ịgbakwunye .dropdown-menu-dark
na .dropdown-menu
.
Offcanvas
Debe ọdịnaya na-apụ apụ ebe a.
<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>
Na-anabata
Agbakwunyere na v5.2.0Klas ndị na-anabata nke ọma na-ezobe ọdịnaya n'èzí ihe nlele site na nkwụsịtụ na ala akọwapụtara. N'elu ebe nkwụsịtụ ahụ, ihe dị n'ime ya ga-eme ka ọ dị na mbụ. Dịka ọmụmaatụ, .offcanvas-lg
na-ezobe ọdịnaya n'ime oghere dị n'okpuru ebe lg
nkwụsịtụ, mana na-egosi ọdịnaya dị n'elu ebe lg
nkwụsịtụ.
Offcanvas na-anabata
Nke a bụ ọdịnaya n'ime .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>
Klas ndị na-anabata enyo dị n'ofe ebe nkwụsịtụ ọ bụla.
.offcanvas
.offcanvas-sm
.offcanvas-md
.offcanvas-lg
.offcanvas-xl
.offcanvas-xxl
Ndokwa
Enweghị ebe ndabere maka ihe ndị na-apụ apụ, yabụ ị ga-agbakwunye otu n'ime klaasị mgbanwe n'okpuru.
.offcanvas-start
dowe anya n'aka ekpe nke ebe nlele (egosiri n'elu).offcanvas-end
dowe anyawa n'aka nri nke ebe nlele.offcanvas-top
na-etinye offcanvas n'elu ebe nlele.offcanvas-bottom
na-etinye offcanvas na ala nke ebe nlele
Nwalee atụ elu, aka nri na ala dị n'okpuru.
N'elu kanvas
<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>
Apụpụ n'aka nri
<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 ala
<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>
Nnweta
Ebe ọ bụ na panetị offcanvas bụ n'ezie mkparịta ụka modal, jide n'aka na ịtinye aria-labelledby="..."
- na-ezo aka aha offcanvas - na .offcanvas
. Mara na ịchọghị ịgbakwunye role="dialog"
ebe ọ bụ na anyị tinyegoro ya site na Javascript.
CSS
Mgbanwe
Agbakwunyere na v5.2.0Dịka akụkụ nke ụzọ mgbanwe mgbanwe CSS nke Bootstrap, offcanvas na-eji mgbanwe CSS mpaghara .offcanvas
emeziwanye maka nhazi oge. A na-edozi ụkpụrụ maka mgbanwe CSS site na Sass, yabụ ka na-akwado nhazi Sass, kwa.
--#{$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};
Sass variables
$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;
Ojiji
Ihe mgbakwunye Offcanvas na-eji klaasị na njirimara ole na ole iji jikwaa ibuli elu:
.offcanvas
na-ezochi ọdịnaya.offcanvas.show
na-egosi ọdịnaya.offcanvas-start
na-ezobe ihe mgbochi dị n'aka ekpe.offcanvas-end
na-ezobe ihe dịpụrụ adịpụ n'aka nri.offcanvas-top
na-ezobe ihe ndị dịpụrụ adịpụ n'elu.offcanvas-bottom
na-ezobe ihe mgbochi dị n'okpuru
Tinye bọtịnụ mkpochapụ nwere data-bs-dismiss="offcanvas"
njirimara, nke na-ebute ọrụ Javascript. Jide n'aka na ị ga-eji <button>
mmewere ya na omume kwesịrị ekwesị n'ofe ngwaọrụ niile.
Site na njirimara data
Tụgharịa
Tinye data-bs-toggle="offcanvas"
na a data-bs-target
ma ọ bụ href
na mmewere iji kenye njikwa nke otu ihe na-apụ apụ na-akpaghị aka. Àgwà ahụ data-bs-target
na-anabata onye nhọpụta CSS iji tinye ihe na-apụ apụ na ya. Jide n'aka na ịtinye klaasị offcanvas
na mmewere offcanvas. Ọ bụrụ na ị ga-achọ ka ọ meghee, tinye klaasị agbakwunyere show
.
Wepụ
Enwere ike nweta nchụpụ site na data
njirimara dị na bọtịnụ dị n'ime oghere dị ka egosiri n'okpuru:
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
ma ọ bụ na bọtịnụ na- abụghị kanvas na-eji ihe a data-bs-target
gosipụtara n'okpuru:
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#my-offcanvas" aria-label="Close"></button>
Site JavaScript
Jiri aka jiri:
const offcanvasElementList = document.querySelectorAll('.offcanvas')
const offcanvasList = [...offcanvasElementList].map(offcanvasEl => new bootstrap.Offcanvas(offcanvasEl))
Nhọrọ
Dịka enwere ike ịfefe nhọrọ site na njirimara data ma ọ bụ Javascript, ị nwere ike itinye aha nhọrọ na data-bs-
, dịka na data-bs-animation="{value}"
. Gbaa mbọ hụ na ị gbanwee ụdị ikpe nke aha nhọrọ site na " camelCase " gaa na " kebab-case " mgbe ị na-agafe nhọrọ site na njirimara data. Dịka ọmụmaatụ, jiri data-bs-custom-class="beautifier"
kama data-bs-customClass="beautifier"
.
Dịka nke Bootstrap 5.2.0, akụrụngwa niile na-akwado njirimara data echekwara nnwaledata-bs-config
nke nwere ike idobe nhazi akụrụngwa dị mfe dị ka eriri JSON. Mgbe mmewere nwere data-bs-config='{"delay":0, "title":123}'
na data-bs-title="456"
njiri mara, uru ikpeazụ title
ga-abụ 456
na njirimara data dị iche ga-ewepụ ụkpụrụ enyere na data-bs-config
. Na mgbakwunye, njirimara data dị adị nwere ike idobe ụkpụrụ JSON dịka data-bs-delay='{"show":0,"hide":150}'
.
Aha | Ụdị | Ọdabara | Nkọwa |
---|---|---|---|
backdrop |
boolean ma ọ bụ eriristatic |
true |
Tinye ihe ndabere na ahụ mgbe a na-apụ apụ na-emeghe. N'aka nke ọzọ, ezipụta static maka backdrop nke na-adịghị emechi oghere anya mgbe ịpịrị ya. |
keyboard |
boolean | true |
Na-emechi oghere anya mgbe ịpịrị igodo mgbapụ. |
scroll |
boolean | false |
Kwe ka ọ pịgharịa ahụ mgbe a na-apụ apụ na-emeghe. |
Ụzọ
Ụzọ asynchronous na ntụgharị
Ụzọ API niile enweghị atụ wee malite mgbanwe . Ha na-alaghachikwuru onye na-akpọ oku ozugbo mgbanwe ahụ malitere mana tupu ya akwụsị . Na mgbakwunye, a ga-eleghara oku usoro na mpaghara mgbanwe anya .
Na-eme ka ọdịnaya gị rụọ ọrụ dị ka ihe na-apụ apụ. Nabata nhọrọ nhọrọ object
.
Ị nwere ike iji onye na-ewu ihe mepụta ihe atụ na-apụ apụ, dịka ọmụmaatụ:
const bsOffcanvas = new bootstrap.Offcanvas('#myOffcanvas')
Usoro | Nkọwa |
---|---|
getInstance |
Usoro kwụ ọtọ nke na-enye gị ohere ịnweta ihe atụ anya nke jikọtara ya na mmewere DOM. |
getOrCreateInstance |
Usoro kwụ ọtọ nke na-enye gị ohere ịnweta ihe atụ anya nke DOM, ma ọ bụ mepụta nke ọhụrụ ma ọ bụrụ na ebidoghị ya. |
hide |
Na-ezobe mmewere apụọ. Na-alaghachikwute onye na-akpọ oku tupu ezobe ihe n'èzí (ya bụ, tupu hidden.bs.offcanvas mmemme emee). |
show |
Na-egosi ihe dịpụrụ adịpụ. Na-alaghachikwute onye na-akpọ oku tupu egosipụta ihe ndị dịpụrụ adịpụ (ya bụ tupu shown.bs.offcanvas mmemme emee). |
toggle |
Na-atụgharị ihe dịpụrụ adịpụ na-egosi ma ọ bụ zoo. Na-alaghachikwute onye na-akpọ oku tupu egosiri ma ọ bụ ezobe ihe ndị na-apụ apụ (ya bụ, tupu ihe shown.bs.offcanvas omume hidden.bs.offcanvas ahụ emee). |
Ihe omume
Klas Offcanvas Bootstrap na-ekpughere ihe omume ole na ole maka itinye aka n'ime ọrụ oyi.
Ụdị mmemme | Nkọwa |
---|---|
hide.bs.offcanvas |
A na-agbapụ ihe omume a ozugbo mgbe hide a na-akpọ usoro ahụ. |
hidden.bs.offcanvas |
A na-agbapụ mmemme a mgbe ezoro ezoro onye ọrụ ihe na-apụ apụ (ga-echere mgbanwe CSS ka agwụchaa). |
hidePrevented.bs.offcanvas |
A na-agbapụ ihe omume a mgbe egosiri offcanvas, ndabere ya bụ static ma pịa n'èzí offcanvas. A na-agbapụkwa mmemme ahụ mgbe ịpịrị igodo ụzọ mgbapụ ma keyboard tọọ nhọrọ ka false . |
show.bs.offcanvas |
Ihe omume a na-agba ọkụ ozugbo show a na-akpọ usoro ihe atụ. |
shown.bs.offcanvas |
A na-agbapụ mmemme a mgbe onye ọrụ mere ka ihe na-apụ apụ anya (ga-echere ntụgharị CSS ka agwụchaa). |
const myOffcanvas = document.getElementById('myOffcanvas')
myOffcanvas.addEventListener('hidden.bs.offcanvas', event => {
// do something...
})