Nwoma mmobɔwee
Yɛ Bootstrap navigation anaa list group components a egyina scroll gyinabea so no foforo ankasa de kyerɛ link a ɛreyɛ adwuma mprempren wɔ viewport no mu.
Scrollspy wɔ ahwehwɛde kakraa bi na ama ayɛ adwuma yiye:
- Sɛ worekyekye yɛn JavaScript no afi fibea a, ɛhwehwɛ sɛ
util.js
. - Ɛsɛ sɛ wɔde di dwuma wɔ Bootstrap nav component anaa list group so .
- Scrollspy hwehwɛ
position: relative;
wɔ element a woreyɛ akwansra so no so, mpɛn pii no<body>
. - Sɛ woreyɛ akwansrafo wɔ nneɛma afoforo a ɛnyɛ
<body>
, hwɛ hu sɛ wowɔheight
set na wode adioverflow-y: scroll;
dwuma. - Ankora (
<a>
) ho hia na ɛsɛ sɛ ɛkyerɛ element bi a ɛwɔ saaid
.
Sɛ wɔde di dwuma yiye a, wo nav anaa list kuw no bɛsesa sɛnea ɛfata, de .active
adesuakuw no afi ade biako so akɔ foforo so a egyina wɔn botae ahorow a ɛbata ho so.
Twe beae a ɛwɔ navbar no ase no na hwɛ adesuakuw a ɛreyɛ adwuma no nsakrae. Wɔbɛtwe adwene asi nneɛma a ɛwɔ ase hɔ no so nso.
@kɛseɛ
Ad leggings keytar, brunch id adwini apontow dolor adwumayɛfo. Pitchfork yr enim lo-fi ansa na wɔretɔn qui. Tumblr afuw-kɔ-pon sakre hokwan ahorow biara. Anim keffiyeh carles a ɔyɛ ɔkwasea. Velit seitan mcsweeney mfonini dan 3 ɔkraman ɔsram irure. Cosby sweater lomo jean shorts, williamsburg hoodie minim qui ebia wontee wɔn ho asɛm et cardigan ahotoso sikakorabea culpa biodiesel wes anderson aesthetic. Nihil tattooed accusamus, cred aseresɛm biodiesel keffiyeh nsaanodwumayɛfo ullamco consequat.
@mdo na ɔkyerɛwee
Veniam marfa mustache skateboard, adipisicing fugiat velit pitchfork beard. Freegan beard aliqua cupidatat mcsweeney's vero. Cupidatat four loko nisi, ea helvetica nulla carles. Tattooed cosby sweater food truck, mcsweeney's quis non freegan vinyl. Lo-fi wes anderson +1 sartorial. Carles non aesthetic exercitation quis gentrify. Brooklyn adipisicing craft beer vice keytar deserunt.
one
Occaecat commodo aliqua delectus. Fap craft beer deserunt skateboard ea. Lomo bicycle rights adipisicing banh mi, velit ea sunt next level locavore single-origin coffee in magna veniam. High life id vinyl, echo park consequat quis aliquip banh mi pitchfork. Vero VHS est adipisicing. Consectetur nisi DIY minim messenger bag. Cred ex in, sustainable delectus consectetur fanny pack iphone.
two
In incididunt echo park, officia deserunt mcsweeney's proident master cleanse thundercats sapiente veniam. Excepteur VHS elit, proident shoreditch +1 biodiesel laborum craft beer. Single-origin coffee wayfarers irure four loko, cupidatat terry richardson master cleanse. Assumenda you probably haven't heard of them art party fanny pack, tattooed nulla cardigan tempor ad. Proident wolf nesciunt sartorial keffiyeh eu banh mi sustainable. Elit wolf voluptate, lo-fi ea portland before they sold out four loko. Locavore enim nostrud mlkshk brooklyn nesciunt.
three
Ad leggings keytar, brunch id art party dolor labore. Pitchfork yr enim lo-fi before they sold out qui. Tumblr farm-to-table bicycle rights whatever. Anim keffiyeh carles cardigan. Velit seitan mcsweeney's photo booth 3 wolf moon irure. Cosby sweater lomo jean shorts, williamsburg hoodie minim qui you probably haven't heard of them et cardigan trust fund culpa biodiesel wes anderson aesthetic. Nihil tattooed accusamus, cred irony biodiesel keffiyeh artisan ullamco consequat.
Keytar twee blog, culpa ɔbɔfo bag marfa nea ɛte biara delectus aduan lɔre. Sapiente synth id a ɛkyerɛ sɛ obi yɛ ade. Locavore sed helvetica cliche irony, aprannaa a ebia wontee wɔn ho asɛm consequat hoodie gluten-free lo-fi fap aliquip. Labore elit placeat ansa na wɔretɔn awie, terry richardson proident brunch nesciunt quis cosby sweater pariatur keffiyeh ut helvetica adwumfo. Cardigan nsaanodwuma beer seitan a wɔasiesie velit. VHS chambray adwuma no yɛ bere tiaa mu veniam. Anim mollit minim commodo ullamco aprannaa a ɛrebɔ.
Scrollspy nso ne nested .nav
s yɛ adwuma. Sɛ nested bi .nav
yɛ a .active
, n'awofo nso bɛyɛ .active
. Twe beae a ɛwɔ navbar no nkyɛn no na hwɛ adesuakuw a ɛreyɛ adwuma no nsakrae.
Adeɛ 1
Ex consequat commodo adipisicing apɔw-mu-teɛteɛ aute excepteur occaecat ullamco duis aliqua id magna ullamco eu. Yɛ aute ipsum ipsum ullamco cillum a wɔde yɛ adwuma no. Fugiat laborum incididunt bere tiaa mu eu nea efi mu ba enim dolore proident. Qui laborum do non excepteur nulla magna eiusmod consectetur in. Aliqua ne nea esii no officia quis ne nea esii no voluptate a ɛnyɛ anim reprehenderit adipisicing dolore ut nea efi mu ba no deserunt mollit dolore. Aliquip nulla enim veniam a ɛnyɛ guankɔbea id cupidat nulla elit cupidatat commodo velit ut eiusmod cupidatat elit dolore.
Asɛm 1-1
Amet bere tiaa mu mollit aliquip pariatur excepteur commodo yɛ ea cillum commodo Lorem ne occaecat elit qui et. Aliquip adwuma ex ex esse voluptate occaecat Lorem ullamco deserunt. Aliqua cillum excepteur a ɛnyɛ nea ɛde ba no id quis ea. Tena ase proident ullamco aute magna pariatur hwene mu adwuma. Reprehenderit aliqua commodo eiusmod aliquip est yɛ duis amet proident magna consectetur a ɛde ba eu commodo guankɔbea a ɛnyɛ quis. Enim aliquip apɔw-mu-teɛteɛ ullamco adipisicing voluptate excepteur apɔw-mu-teɛteɛ ketewaa bi minim commodo adipisicing apɔw-mu-teɛteɛ officia nisi adipisicing. Anim id duis qui consequat adwuma adipisicing bɔne dolor elit cillum anim ne guankɔbea.
Asɛm 2-2
Cillum nisi deserunt magna eiusmod qui eiusmod velit voluptate pariatur laborum sunt enim. Irure laboris mollit consequat incididunt sint et culpa culpa incididunt adipisicing magna magna occaecat. Nulla ipsum cillum eiusmod sint elit excepteur ea labore enim consectetur in labore anim. Proident ullamco ipsum esse elit ut Lorem eiusmod dolor et eiusmod. Anim occaecat nulla in non consequat eiusmod velit incididunt.
Item 2
Quis magna Lorem anim amet ipsum do mollit sit cillum voluptate ex nulla tempor. Laborum consequat non elit enim exercitation cillum aliqua consequat id aliqua. Esse ex consectetur mollit voluptate est in duis laboris ad sit ipsum anim Lorem. Incididunt veniam velit elit elit veniam Lorem aliqua quis ullamco deserunt sit enim elit aliqua esse irure. Laborum nisi sit est tempor laborum mollit labore officia laborum excepteur commodo non commodo dolor excepteur commodo. Ipsum fugiat ex est consectetur ipsum commodo tempor sunt in proident.
Item 3
Quis anim sit do amet fugiat dolor velit sit ea ea do reprehenderit culpa duis. Nostrud aliqua ipsum fugiat minim proident occaecat excepteur aliquip culpa aute tempor reprehenderit. Deserunt tempor mollit elit ex pariatur dolore velit fugiat mollit culpa irure ullamco est ex ullamco excepteur.
Item 3-1
Deserunt quis elit Lorem eiusmod amet enim enim amet minim Lorem proident nostrud. Ea id dolore anim exercitation aute fugiat labore voluptate cillum do laboris labore. Ex velit exercitation nisi enim labore reprehenderit labore nostrud ut ut. Esse officia sunt duis aliquip ullamco tempor eiusmod deserunt irure nostrud irure. Ullamco proident veniam laboris ea consectetur magna sunt ex exercitation aliquip minim enim culpa occaecat exercitation. Est tempor excepteur aliquip laborum consequat do deserunt laborum esse eiusmod irure proident ipsum esse qui.
Item 3-2
Labore tena ase culpa commodo elit adipisicing tena ase aliquip elit proident voluptate minim mollit nostrud aute reprehenderit yɛ. Mollit excepteur eu Lorem ipsum anim commodo sint adwuma Lorem wɔ apɔw-mu-teɛteɛ mu velit incididunt. Occaecat consectetur nisi wɔ occaecat proident minim enim sunt reprehenderit apɔw-mu-teɛteɛ cupidat ne yɛ adwuma. Aliquip consequat ad adwuma adwuma mollit ut amet. Tena pariatur bere tiaa mu proident wɔ veniam culpa aliqua mu gye sɛ elit magna fugiat eiusmod amet officia.
Scrollspy nso de .list-group
s yɛ adwuma. Twe beae a ɛwɔ list kuw no nkyɛn no na hwɛ adesuakuw a ɛreyɛ adwuma no nsakrae.
Adeɛ 1
Ex consequat commodo adipisicing apɔw-mu-teɛteɛ aute excepteur occaecat ullamco duis aliqua id magna ullamco eu. Yɛ aute ipsum ipsum ullamco cillum a wɔde yɛ adwuma no. Fugiat laborum incididunt bere tiaa mu eu nea efi mu ba enim dolore proident. Qui laborum do non excepteur nulla magna eiusmod consectetur in. Aliqua ne nea esii no officia quis ne nea esii no voluptate a ɛnyɛ anim reprehenderit adipisicing dolore ut nea efi mu ba no deserunt mollit dolore. Aliquip nulla enim veniam a ɛnyɛ guankɔbea id cupidat nulla elit cupidatat commodo velit ut eiusmod cupidatat elit dolore.
Adeɛ 2
Quis magna Lorem anim amet ipsum yɛ mollit tena cillum voluptate ex nulla bere tiaa mu. Laborum consequat non elit enim apɔw-mu-teɛteɛ cillum aliqua nea efi mu ba id aliqua. Esse ex consectetur mollit voluptate est wɔ duis adwumayɛ mu ad sit ipsum anim Lorem. Incididunt veniam velit elit elit veniam Lorem a ɔyɛ ɔkwasea a ɔyɛ ɔkwasea no tena ase a ɔyɛ ɔkwasea a ɔyɛ ɔkwasea. Laborum nisi sit est bere tiaa mu adwuma mollit adwuma officia adwuma a ɛnyɛ commodo non commodo dolor excepteur commodo. Ipsum fugiat ex est consectetur ipsum commodo bere tiaa mu sunt wɔ proident mu.
Adeɛ 3
Quis anim tena ase yɛ amet fugiat dolor velit tena ea ea yɛ reprehenderit culpa duis. Nostrud aliqua ipsum fugiat minim proident occaecat gye sɛ ɛyɛ aduru a ɛma obi ho kyere no. Deserunt tempor mollit elit ex pariatur dolore velit guankɔbea mollit culpa irure ullamco est ex ullamco gye sɛ obi yɛ ɔkwasea.
Adeɛ 4
Quis anim tena ase yɛ amet fugiat dolor velit tena ea ea yɛ reprehenderit culpa duis. Nostrud aliqua ipsum fugiat minim proident occaecat gye sɛ ɛyɛ aduru a ɛma obi ho kyere no. Deserunt tempor mollit elit ex pariatur dolore velit guankɔbea mollit culpa irure ullamco est ex ullamco gye sɛ obi yɛ ɔkwasea.
Sɛnea ɛbɛyɛ a ɛbɛyɛ mmerɛw sɛ wode scrollspy suban bɛka wo topbar navigation no ho a, fa ka data-spy="scroll"
element a wopɛ sɛ wohwɛ so no ho (mpɛn pii no eyi bɛyɛ <body>
). Afei fa data-target
attribute no ka ID anaa class a ɛwɔ ɔwofo element a ɛwɔ Bootstrap .nav
component biara mu no ho.
Sɛ wode position: relative;
wo CSS no ka ho wie a, frɛ scrollspy no fa JavaScript so:
ID botae ahorow a wobetumi asiesie a ɛho hia
Ɛsɛ sɛ Navbar link ahorow no nya id botae ahorow a wobetumi asiesie. Sɛ nhwɛso no, <a href="#home">home</a>
ɛsɛ sɛ a ne biribi a ɛwɔ DOM no mu te sɛ <div id="home"></div>
.
Wɔabu :visible
wɔn ani agu nneɛma a ɛnyɛ botae so
Wɔbɛbu ani agu target elements a ɛnsɛ :visible
sɛ jQuery kyerɛ no so na wɔrensi wɔn nav nneɛma a ɛne no hyia no so dua da.
Sɛ wode scrollspy di dwuma de ka nneɛma a wode bɛka ho anaa woayi afi DOM no mu ho a, ɛho behia sɛ wofrɛ refresh kwan no te sɛ saa:
Ɔsɛe element bi scrollspy.
Wobetumi afa data attributes anaa JavaScript so de nneɛma a wobɛpaw no akɔ. Sɛ wopɛ data su ahorow a, fa option din no ka ho data-
, sɛnea ɛwɔ data-offset=""
.
Din | Korɔ | Mfiaseɛ | Nkyerɛmu |
---|---|---|---|
offset a wɔde hyɛ mu | nɔma | 10. 10 | Pixels to offset fi soro bere a worebu gyinabea a scroll no. |
Nsɛm a Ɛsisii no Su | Nkyerɛmu |
---|---|
yɛ adwuma.bs.scrollspy | Saa adeyɛ yi tow wɔ nhoma mmobɔwee element no so bere biara a ade foforo bi bɛyɛ adwuma denam nhoma mmobɔwee no so. |