Scrollspy
Hoʻohou ʻakomi i ka hoʻokele Bootstrap a i ʻole ka papa inoa o nā ʻāpana hui e pili ana i ke kūlana ʻōwili e hōʻike i ka loulou e hana nei i kēia manawa ma ka viewport.
Loaʻa iā Scrollspy kekahi mau koi e hana pono ai:
- Inā ʻoe e kūkulu nei i kā mākou JavaScript mai ke kumu, pono
util.js
ia . - Pono e hoʻohana ʻia ma kahi ʻāpana Bootstrap nav a i ʻole pūʻulu papa inoa .
- Pono ʻo Scrollspy i
position: relative;
ka mea āu e mākaʻikaʻi nei, maʻamau ka<body>
. - Ke kiu i nā mea ʻē aʻe ma mua o ka
<body>
, e ʻike pono e loaʻa kahiheight
hoʻonohonoho aoverflow-y: scroll;
hoʻohana ʻia. - Pono nā heleuma (
<a>
) a pono e kuhikuhi i kahi mea me kēlāid
.
Ke hoʻokō maikaʻi ʻia, e hōʻano hou kāu nav a i ʻole pūʻulu papa inoa e like me ka neʻe ʻana o ka .active
papa mai kahi mea a i kekahi mea e pili ana i kā lākou mau pahuhopu pili.
E ʻōwili i ka ʻāpana ma lalo o ka navbar a nānā i ka loli o ka papa hana. E hōʻike ʻia nā mea hāʻule i lalo.
@momona
Ad leggings keytar, brunch id art party dolor labore. Pitchfork yr enim lo-fi ma mua o ko lākou kūʻai ʻana aku. Tumblr pāʻani-a-papaʻaina kuleana paikikala i kēlā me kēia mea. Anim keffiyeh carles cardigan. ʻO ka pahu kiʻi a Velit seitan mcsweeney 3 wolf moon irure. ʻO Cosby sweater lomo jean shorts, williamsburg hoodie minim qui ʻaʻole paha ʻoe i lohe iā lākou a me ka cardigan trust fund culpa biodiesel wes anderson aesthetic. Nihil tattooed accusamus, cred irony biodiesel keffiyeh artisan ullamco consequat.
@mdo
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 messenger bag marfa whatever delectus food truck. Sapiente synth id assumenda. Locavore sed helvetica cliche irony, thundercats ʻaʻole paha ʻoe i lohe no lākou consequat hoodie gluten-free lo-fi fap aliquip. Ma mua o ke kūʻai ʻia ʻana aku, ʻo terry richardson proident brunch nesciunt quis cosby sweater pariatur keffiyeh ut helvetica artisan. Cardigan craft beer seitan readymade velit. VHS chambray laboris tempor veniam. Anim mollit minim commodo ullamco thundercats.
Hoʻohana pū ʻo Scrollspy me nā nested .nav
s. Inā he pūnana .nav
, ʻo .active
kona mau mākua pū kekahi .active
. E ʻōwili i ka ʻāpana e pili ana i ka navbar a nānā i ka hoʻololi ʻana o ka papa hana.
'ikamu 1
Ex consequat commodo adipisicing exercitation aute excepteur occaecat ullamco duis aliqua id magna ullamco eu. Do aute ipsum ipsum ullamco cillum consectetur ut et aute consectetur labore. Fugit laborum incididunt tempor eu consequat enim dolore proident. Qui laborum do non excepteur nulla magna eiusmod consectetur in. Aliqua et aliqua officia quis et incididunt voluptate non anim reprehenderit adipisicing dolore ut consequat deserunt mollit dolore. Aliquip nulla enim veniam non fugiat id cupidatat nulla elit cupidatat commodo velit ut eiusmod cupidatat elit dolore.
Kumuhana 1-1
Amet tempor mollit aliquip pariatur excepteur commodo do ea cillum commodo Lorem et occaecat elit qui et. Aliquip labore ex ex esse voluptate occaecat Lorem ullamco deserunt. Aliqua cillum excepteur irure consequat id quis ea. Noho pono ullamco aute magna pariatur nostrud labore. Reprehenderit aliqua commodo eiusmod aliquip est do duis amet proident magna consectetur consequat eu commodo fugiat non quis. Enim aliquip exercitation ullamco adipisicing voluptate excepteur minim exercitation minim minim commodo adipisicing exercitation officia nisi adipisicing. Anim id duis qui consequat labore adipisicing sint dolor elit cillum anim et fugiat.
Kumuhana 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
E ho'āʻo e hoʻopau i ka hana. Mollit excepteur eu Lorem ipsum anim commodo sint labore Lorem in exercitation velit incididunt. Occaecat consectetur nisi in occaecat proident minim enim sunt reprehenderit exercitation cupidatat and do officia. Aliquip consequat ad laboure laboure mollit ut amet. Noho maikaʻi ʻia i loko o ka ʻāpana aliʻi ʻokoʻa wale nō elit magna fugiat eiusmod amet officia.
Hana pū ʻo Scrollspy me .list-group
s. E ʻōwili i ka ʻāpana ma ka ʻaoʻao o ka pūʻulu papa inoa a nānā i ka hoʻololi ʻana o ka papa hana.
'ikamu 1
Ex consequat commodo adipisicing exercitation aute excepteur occaecat ullamco duis aliqua id magna ullamco eu. Do aute ipsum ipsum ullamco cillum consectetur ut et aute consectetur labore. Fugit laborum incididunt tempor eu consequat enim dolore proident. Qui laborum do non excepteur nulla magna eiusmod consectetur in. Aliqua et aliqua officia quis et incididunt voluptate non anim reprehenderit adipisicing dolore ut consequat deserunt mollit dolore. Aliquip nulla enim veniam non fugiat id cupidatat nulla elit cupidatat commodo velit ut eiusmod cupidatat elit dolore.
'ikamu 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 fugit ex est consectetur ipsum commodo tempor sunt in proident.
'ikamu 3
Quis anim sit do amet fugiat dolor velit sit ea ea do reprehenderit culpa duis. Nostrud aliqua ipsum fugit 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.
Kumuhana 4
Quis anim sit do amet fugiat dolor velit sit ea ea do reprehenderit culpa duis. Nostrud aliqua ipsum fugit 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.
No ka hoʻohui maʻalahi i ka hana scrollspy i kāu hoʻokele topbar, e hoʻohui data-spy="scroll"
i ka mea āu e makemake ai e kiu (ʻo ka mea maʻamau ʻo ia ka <body>
). A laila e hoʻohui i ke data-target
ʻano me ka ID a i ʻole ka papa o ka mea makua o kekahi ʻāpana Bootstrap .nav
.
Ma hope o ka hoʻohui position: relative;
ʻana i kāu CSS, e kāhea i ka scrollspy ma o JavaScript:
Pono nā pahuhopu ID hiki ke hoʻoholo
Pono nā loulou Navbar i nā pahuhopu id hiki ke hoʻoholo. No ka laʻana, <a href="#home">home</a>
pono e pili i kekahi mea ma ka DOM e like me <div id="home"></div>
.
Ua nānā ʻole ʻia :visible
nā mea ʻaʻole i manaʻo ʻia
E nānā ʻole ʻia nā mea kikoʻī ʻaʻole :visible
e like me ka jQuery a ʻaʻole e hōʻike ʻia kā lākou mau mea nav pili.
Ke hoʻohana nei i ka scrollspy me ka hoʻohui a wehe ʻana paha i nā mea mai ka DOM, pono ʻoe e kāhea i ke ʻano hoʻomaha e like me:
Hoʻopau i ka scrollspy o kekahi mea.
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-
, e like me ka data-offset=""
.
inoa | ʻAno | Default | wehewehe |
---|---|---|---|
offset | helu | 10 | Pikika e hoʻoneʻe mai luna mai ke helu ʻana i ke kūlana o ka ʻōwili. |
ʻAno Hanana | wehewehe |
---|---|
activate.bs.scrollspy | Hoʻomaka kēia hanana i ka mea scroll i ka wā e hoʻāla ʻia ai kahi mea hou e ka scrollspy. |