Tuvaldan tashqari
Bir nechta sinflar va JavaScript plaginimiz yordamida loyihangizda navigatsiya, xarid qilish aravachalari va boshqalar uchun yashirin yon panellarni yarating.
U qanday ishlaydi
Offcanvas yon panel komponenti boʻlib, JavaScript orqali koʻrish oynasining chap, oʻng, yuqori yoki pastki chetidan paydo boʻlishi mumkin. Tugmalar yoki langarlar siz almashtiradigan muayyan elementlarga biriktirilgan trigger sifatida ishlatiladi va data
atributlar bizning JavaScript-ni chaqirish uchun ishlatiladi.
- Offcanvas modallar bilan bir xil JavaScript kodlarini baham ko'radi. Kontseptual jihatdan ular juda o'xshash, ammo ular alohida plaginlardir.
- Xuddi shunday, offcanvas uslublari va o'lchamlari uchun ba'zi manba Sass o'zgaruvchilari modal o'zgaruvchilaridan meros qilib olinadi.
- Ko'rsatilganda, offcanvas birlamchi fonni o'z ichiga oladi, uni bosish orqali kanvasni yashirish mumkin.
- Modallarga o'xshab, bir vaqtning o'zida faqat bitta offcanvas ko'rsatilishi mumkin.
Oldindan qisqa ma'lumot berish! CSS animatsiyalarni qanday ishlashini hisobga olsak, siz margin
yoki translate
elementdan foydalana olmaysiz .offcanvas
. Buning o'rniga, sinfni mustaqil o'rash elementi sifatida foydalaning.
prefers-reduced-motion
media so'roviga bog'liq. Maxsus imkoniyatlar hujjatlarimizning qisqartirilgan harakat bo'limiga qarang
.
Misollar
Offcanvas komponentlari
.show
Quyida sukut bo'yicha ( on orqali) ko'rsatilgan offcanvas misoli keltirilgan .offcanvas
. Offcanvas, o'chirish tugmasi va ba'zi bir boshlang'ich uchun ixtiyoriy tana sinfiga ega bo'lgan sarlavhani qo'llab-quvvatlashni o'z ichiga oladi padding
. Iloji bo'lsa, rad etish amallari bilan offcanvas sarlavhalarini qo'shishni yoki ochiq-oydin rad etish amalini taqdim etishingizni tavsiya qilamiz.
Tuvaldan tashqari
<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>
Jonli demo
.show
Quyidagi tugmalardan foydalanib, klass bilan elementdagi sinfni almashtiradigan offcanvas elementini JavaScript orqali ko'rsatish va yashirish uchun foydalaning .offcanvas
.
.offcanvas
kontentni yashiradi (standart).offcanvas.show
mazmunini ko‘rsatadi
Siz atributli havoladan href
yoki atributli tugmachadan foydalanishingiz mumkin data-bs-target
. Ikkala holatda data-bs-toggle="offcanvas"
ham talab qilinadi.
Tuvaldan tashqari
<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>
Tanani aylantirish
<body>
Tuvaldan tashqari rasm va uning foni ko'rinadigan bo'lsa , elementni aylantirish o'chirib qo'yiladi. O'tkazishni data-bs-scroll
yoqish uchun atributdan foydalaning .<body>
Tanani aylantiruvchi kanvas
Ushbu parametrni amalda ko'rish uchun sahifaning qolgan qismini aylantirib ko'ring.
<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>
Badanni aylantirish va fon
<body>
Ko'rinadigan fon bilan aylantirishni ham yoqishingiz mumkin .
O'tkazish bilan fon
Ushbu parametrni amalda ko'rish uchun sahifaning qolgan qismini aylantirib ko'ring.
<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>
Statik fon
Fon statik holatga o'rnatilgan bo'lsa, uning tashqarisiga bosilganda offcanvas yopilmaydi.
Tuvaldan tashqari
<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>
To'q rangli tuval
5.2.0 versiyasida qo'shilganTo'q rangli navbarlar kabi turli kontekstlarga yaxshiroq moslashtirish uchun yordam dasturlari yordamida tasvirdan tashqari rasmlarning ko'rinishini o'zgartiring. Bu erda biz to'q rangli tuval bilan to'g'ri uslublash uchun .text-bg-dark
va .offcanvas
ga .btn-close-white
qo'shamiz . .btn-close
Agar sizda ochiladigan menyular bo'lsa, ga qo'shishni ham o'ylab .dropdown-menu-dark
ko'ring .dropdown-menu
.
Tuvaldan tashqari
Tuvaldan tashqari kontentni bu yerga joylashtiring.
<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>
Javobgar
5.2.0 versiyasida qo'shilganResponsive offcanvas sinflari ko'rish oynasidan tashqaridagi kontentni belgilangan to'xtash nuqtasidan va pastga yashiradi. Ushbu to'xtash nuqtasidan yuqoridagi tarkib odatdagidek harakat qiladi. Masalan, to'xtash nuqtasi .offcanvas-lg
ostidagi tarkibni yopiq kanvasda yashiradi lg
, lekin to'xtash nuqtasi ustidagi tarkibni ko'rsatadi lg
.
Tuvaldan tashqari sezgir
Bu bir ichidagi tarkibdir .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>
Har bir to'xtash nuqtasi uchun javob beruvchi offcanvas sinflari mavjud.
.offcanvas
.offcanvas-sm
.offcanvas-md
.offcanvas-lg
.offcanvas-xl
.offcanvas-xxl
Joylashtirish
Offcanvas komponentlari uchun standart joylashuv mavjud emas, shuning uchun siz quyidagi modifikator sinflaridan birini qo'shishingiz kerak.
.offcanvas-start
kanvasni ko'rish oynasining chap tomoniga joylashtiradi (yuqorida ko'rsatilgan).offcanvas-end
offcanvasni ko'rish oynasining o'ng tomoniga joylashtiradi.offcanvas-top
offcanvasni ko'rish oynasining yuqori qismiga joylashtiradi.offcanvas-bottom
offcanvasni ko'rish oynasining pastki qismiga joylashtiradi
Quyida yuqori, o'ng va pastki misollarni sinab ko'ring.
Tuvaldan tashqari tepa
<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 to'g'ri
<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>
Tuvaldan tashqari pastki
<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>
Foydalanish imkoniyati
Offcanvas paneli kontseptual ravishda modal dialog aria-labelledby="..."
bo'lganligi sababli, -ga - offcanvas sarlavhasiga havola - qo'shishni unutmang .offcanvas
. E'tibor bering, siz qo'shishingiz shart emas, role="dialog"
chunki biz uni allaqachon JavaScript orqali qo'shdik.
CSS
O'zgaruvchilar
5.2.0 versiyasida qo'shilganBootstrap-ning rivojlanayotgan CSS o'zgaruvchilari yondashuvining bir qismi sifatida offcanvas endi .offcanvas
real vaqt rejimida yaxshilangan sozlash uchun mahalliy CSS o'zgaruvchilardan foydalanadi. CSS o'zgaruvchilari uchun qiymatlar Sass orqali o'rnatiladi, shuning uchun Sass moslashuvi hali ham qo'llab-quvvatlanadi.
--#{$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 o'zgaruvchilari
$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;
Foydalanish
Offcanvas plagini og'ir yuklarni ko'tarish uchun bir nechta sinflar va atributlardan foydalanadi:
.offcanvas
mazmunini yashiradi.offcanvas.show
mazmunini ko‘rsatadi.offcanvas-start
chapdagi tuvaldan tashqarini yashiradi.offcanvas-end
o'ng tarafdagi kanvasni yashiradi.offcanvas-top
yuqoridagi kanvasni yashiradi.offcanvas-bottom
pastki qismidagi kanvasni yashiradi
data-bs-dismiss="offcanvas"
JavaScript funksiyasini ishga tushiradigan atributli o'chirish tugmachasini qo'shing . <button>
Barcha qurilmalarda to'g'ri harakat qilish uchun u bilan elementdan foydalanganingizga ishonch hosil qiling .
Ma'lumotlar atributlari orqali
Oʻchirish
Bir offcanvas elementning boshqaruvini avtomatik belgilash uchun elementga data-bs-toggle="offcanvas"
va a data-bs-target
yoki qo'shing . href
Atribut offcanvasni data-bs-target
qo'llash uchun CSS selektorini qabul qiladi. offcanvas
Sinfni offcanvas elementiga qo'shganingizga ishonch hosil qiling . Agar siz uni sukut bo'yicha ochishni istasangiz, qo'shimcha sinfni qo'shing show
.
Rad etish
Ishdan bo'shatishga quyida ko'rsatilgandek , offcanvas ichidagi tugmadagidata
atribut yordamida erishish mumkin:
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
yoki quyida ko'rsatilganidek , tuvaldan tashqaridagi tugmachada:data-bs-target
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#my-offcanvas" aria-label="Close"></button>
JavaScript orqali
Qo'lda yoqish:
const offcanvasElementList = document.querySelectorAll('.offcanvas')
const offcanvasList = [...offcanvasElementList].map(offcanvasEl => new bootstrap.Offcanvas(offcanvasEl))
Variantlar
data-bs-
Variantlar ma'lumotlar atributlari yoki JavaScript orqali uzatilishi mumkinligi sababli , ga variant nomini qo'shishingiz mumkin data-bs-animation="{value}"
. Variantlarni maʼlumotlar atributlari orqali oʻtkazishda variant nomining registr turini “ camelCase ” dan “ kabob-case ” ga oʻzgartirganingizga ishonch hosil qiling. Masalan, data-bs-custom-class="beautifier"
o'rniga foydalaning data-bs-customClass="beautifier"
.
Bootstrap 5.2.0 dan boshlab barcha komponentlar JSON qatori sifatida oddiy komponent konfiguratsiyasini joylashtirishi mumkin bo‘lgan eksperimental zaxiralangan ma’lumotlar atributini qo‘llab-quvvatlaydi. data-bs-config
Element data-bs-config='{"delay":0, "title":123}'
va data-bs-title="456"
atributlariga ega bo'lsa, yakuniy title
qiymat bo'ladi 456
va alohida ma'lumotlar atributlari ga berilgan qiymatlarni bekor qiladi data-bs-config
. Bundan tashqari, mavjud ma'lumotlar atributlari kabi JSON qiymatlarini joylashtirishi mumkin data-bs-delay='{"show":0,"hide":150}'
.
Ism | Turi | Standart | Tavsif |
---|---|---|---|
backdrop |
mantiqiy yoki satrstatic |
true |
Offcanvas ochiq bo'lganda tanaga fon suring. Shu bilan bir qatorda, static bosilganda kanvasni yopmaydigan fon uchun belgilang. |
keyboard |
mantiqiy | true |
Escape tugmasi bosilganda, offcanvasni yopadi. |
scroll |
mantiqiy | false |
Offcanvas ochiq bo'lganda tanani aylantirishga ruxsat bering. |
Usullari
Asinxron usullar va o'tishlar
Barcha API usullari asenkron va o'tishni boshlaydi . O'tish boshlanishi bilanoq, lekin tugashidan oldin ular qo'ng'iroq qiluvchiga qaytadilar . Bundan tashqari, o'tish komponentidagi usul chaqiruvi e'tiborga olinmaydi .
Qo'shimcha ma'lumot olish uchun bizning JavaScript hujjatlariga qarang .
Kontentingizni kanvasdan tashqari element sifatida faollashtiradi. Ixtiyoriy variantlarni qabul qiladi object
.
Siz konstruktor yordamida offcanvas misolini yaratishingiz mumkin, masalan:
const bsOffcanvas = new bootstrap.Offcanvas('#myOffcanvas')
Usul | Tavsif |
---|---|
getInstance |
DOM elementi bilan bog'langan offcanvas misolini olish imkonini beruvchi statik usul. |
getOrCreateInstance |
DOM elementi bilan bog'langan offcanvas misolini olish yoki ishga tushirilmagan bo'lsa, yangisini yaratish imkonini beruvchi statik usul. |
hide |
Offcanvas elementini yashiradi. Offcanvas elementi haqiqatda yashirilishidan oldin (ya'ni hidden.bs.offcanvas voqea sodir bo'lishidan oldin) qo'ng'iroq qiluvchiga qaytadi. |
show |
Offcanvas elementini ko'rsatadi. Offcanvas elementi haqiqatda ko'rsatilishidan oldin (ya'ni shown.bs.offcanvas voqea sodir bo'lishidan oldin) qo'ng'iroq qiluvchiga qaytadi. |
toggle |
Offcanvas elementini ko'rsatish yoki yashirishga o'zgartiradi. Offcanvas elementi haqiqatda ko'rsatilishi yoki yashirilishidan oldin (ya'ni shown.bs.offcanvas yoki hidden.bs.offcanvas hodisa sodir bo'lishidan oldin) qo'ng'iroq qiluvchiga qaytadi. |
Voqealar
Bootstrap-ning offcanvas klassi offcanvas funksiyasiga ulanish uchun bir nechta hodisalarni ochib beradi.
Tadbir turi | Tavsif |
---|---|
hide.bs.offcanvas |
Ushbu hodisa hide usul chaqirilgandan so'ng darhol o'chiriladi. |
hidden.bs.offcanvas |
Ushbu hodisa offcanvas elementi foydalanuvchidan yashirilganda ishga tushiriladi (CSS o'tishlari tugashini kutadi). |
hidePrevented.bs.offcanvas |
Bu hodisa tuvaldan tashqari tasvir ko'rsatilganda, uning fonida static va tuvaldan tashqarida chertish amalga oshirilganda ishga tushiriladi. Escape tugmasi bosilganda va keyboard opsiya ga o'rnatilganda ham hodisa o'chiriladi false . |
show.bs.offcanvas |
Ushbu hodisa show misol usuli chaqirilganda darhol ishga tushadi. |
shown.bs.offcanvas |
Ushbu hodisa offcanvas elementi foydalanuvchiga ko'rinadigan qilib qo'yilganda ishga tushiriladi (CSS o'tishlari tugashini kutadi). |
const myOffcanvas = document.getElementById('myOffcanvas')
myOffcanvas.addEventListener('hidden.bs.offcanvas', event => {
// do something...
})