Source

Scrollspy ye

Bootstrap navigation walima list group components kuraya i yɛrɛma ka da scroll position kan walasa k’a jira link min bɛ baara la sisan viewport kɔnɔ.

A bɛ baara kɛ cogo min na

Scrollspy bɛ ni wajibi damadɔw ye walasa ka baara kɛ ka ɲɛ:

  • N'i bɛ an ka JavaScript jɔ ka bɔ source la, a bɛ wajibiyautil.js .
  • a ka kan ka baara kɛ Bootstrap nav yɔrɔ dɔ kan walima lisi kulu dɔ kan .
  • Scrollspy bɛ ɲini position: relative;fɛn min kan i bɛ ka sɛgɛsɛgɛli kɛ, a ka c’a la, o ye <body>.
  • Ni aw bɛ fɛn wɛrɛw sɛgɛsɛgɛ minnu tɛ <body>, aw ye aw jija ka heightseti sɔrɔ ani ka a overflow-y: scroll;waleya.
  • Ankɔri ( <a>) wajibiyalen don wa u ka kan ka fɛn dɔ jira ni o ye id.

Ni a waleyara ka ɲɛ, i ka nav walima list kulu bɛna kuraya ka kɛɲɛ n’o ye, ka .activekalasi bɔ fɛn dɔ la ka taa fɛn wɛrɛ la ka da u ni ɲɔgɔn cɛ laɲiniw kan.

Misali la navbar kɔnɔ

Aw ye yɔrɔ lajɛ min bɛ navbar jukɔrɔ ani ka kalansen min bɛ baara kɛ, o yeli ye. Fɛn minnu bɛ bɔ duguma, olu fana bɛna jira.

@belebeleba

Annonce leggings keytar, brunch id art fête dolor labore. Bamako, Mali. Pitchfork yr enim lo-fi sani u ka qui. Tumblr foro-ka-tabali bisikili josariyaw fɛn o fɛn. Anim keffiyeh carles ka kari. Velit seitan mcsweeney ka fototalan 3 waraba kalo irure. Cosby sweater lomo jean shorts, williamsburg hoodie minim qui n'a sɔrɔ i ma u mɛn et cardigan fond de confiance culpa biodiesel wes anderson esthétique. Nihil tatouage accusamus, cred ironie biodiesel keffiyeh artisan ullamco consequat.

@mdo ye

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 ciden sakɔsi marfa fɛn o fɛn delectus dumuni kamiyɔn. Sapiente sinteti id assumenda. Locavore sed helvetica cliche irony, sanpɛrɛnw i bɛ se ka u ma mɛn u la consequat hoodie gluten-free lo-fi fap aliquip. Laboure elit placeat sanni u ka feere ka ban, terry richardson proident brunch nesciunt quis cosby sweater pariatur keffiyeh ut helvetica artisan. Cardigan artisanat bière seitan labɛnnen velit. VHS chambray laboris ye muso ye min bɛ wele ko veniam tempor. Anim mollit minim commodo ullamco sanpɛrɛnw.

<nav id="navbar-example2" class="navbar navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar</a>
  <ul class="nav nav-pills">
    <li class="nav-item">
      <a class="nav-link" href="#fat">@fat</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="#mdo">@mdo</a>
    </li>
    <li class="nav-item dropdown">
      <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Dropdown</a>
      <div class="dropdown-menu">
        <a class="dropdown-item" href="#one">one</a>
        <a class="dropdown-item" href="#two">two</a>
        <div role="separator" class="dropdown-divider"></div>
        <a class="dropdown-item" href="#three">three</a>
      </div>
    </li>
  </ul>
</nav>
<div data-spy="scroll" data-target="#navbar-example2" data-offset="0">
  <h4 id="fat">@fat</h4>
  <p>...</p>
  <h4 id="mdo">@mdo</h4>
  <p>...</p>
  <h4 id="one">one</h4>
  <p>...</p>
  <h4 id="two">two</h4>
  <p>...</p>
  <h4 id="three">three</h4>
  <p>...</p>
</div>

Misali ni nested nav

Scrollspy fana bɛ baara Kɛ ni nested .navs ye. ni nested .navye .active, a bangebagaw fana bɛna kɛ .active. Yɔrɔ min bɛ navbar kɛrɛfɛ, i ka o lajɛ ani ka kalansen min bɛ baara kɛ, o fɛn caman Changement lajɛ.

Fɛn 1nan

Ex consequat commodo adipisicing farikoloɲɛnajɛ aute excepteur occaecat ullamco duis aliqua id magna ullamco eu. Aw bɛ aute ipsum ipsum ullamco cillum consectetur kɛ ani ka aute consectetur baara kɛ. Fugiat laborum incididunt tempor eu kɔlɔlɔ ye enim dolore proident ye. Qui laborum do non excepteur nulla magna eiusmod consectetur in. Aliqua et aliqua officia quis et incididunt voluptate non anim reprehenderit farali dolore ut consequat deserunt mollit dolore. Aliquip nulla enim veniam non fugiat id cupidat nulla elit kupidat commodo velit ut eiusmod kupidata elit dolore.

Fɛn 1-1nan

Amet tempor mollit aliquip pariatur excepteur komodo do ea cillum komodo Lorem ni occaecat elit qui et. Aliquip ye baara kɛ ex ex esse voluptate occaecat Lorem ullamco deserunt. Aliqua cillum excepteur irure kɔlɔlɔ id quis ea. Sigida proident ullamco aute magna pariatur nugu baara. Reprehenderit aliqua commodo eiusmod aliquip est do duis amet proident magna consectetur consequat eu komodo bolila non quis. Enim aliquip farikoloɲɛnajɛ ullamco adipisicing voluptate excepteur minima farikoloɲɛnajɛ minima minima commodo adipisicing farikoloɲɛnajɛ officia nisi adipisicing. Anim id duis qui consequat baara adipisicing sint dolor elit cillum ani fugiat.

Fɛn 2-2nan

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 sigi culpa commodo elit adipisicing sigi aliquip elit proident voluptate minim mollit nostrud aute reprehenderit kɛ. Mollit excepteur eu Lorem ipsum anim commodo sint baara Lorem ka farikoloɲɛnajɛ velit incididunt. Occaecat consectetur nisi in occaecat proident minim enim sunt ka degeliw jalaki cupidatat et do officia. Aliquip consequat ad baara baara mollit ut amet. Aw bɛ sigi pariatur tempor proident la veniam culpa aliqua kɔnɔ excepteur elit magna fugiat eiusmod amet officia.

<nav id="navbar-example3" class="navbar navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar</a>
  <nav class="nav nav-pills flex-column">
    <a class="nav-link" href="#item-1">Item 1</a>
    <nav class="nav nav-pills flex-column">
      <a class="nav-link ml-3 my-1" href="#item-1-1">Item 1-1</a>
      <a class="nav-link ml-3 my-1" href="#item-1-2">Item 1-2</a>
    </nav>
    <a class="nav-link" href="#item-2">Item 2</a>
    <a class="nav-link" href="#item-3">Item 3</a>
    <nav class="nav nav-pills flex-column">
      <a class="nav-link ml-3 my-1" href="#item-3-1">Item 3-1</a>
      <a class="nav-link ml-3 my-1" href="#item-3-2">Item 3-2</a>
    </nav>
  </nav>
</nav>

<div data-spy="scroll" data-target="#navbar-example3" data-offset="0">
  <h4 id="item-1">Item 1</h4>
  <p>...</p>
  <h5 id="item-1-1">Item 1-1</h5>
  <p>...</p>
  <h5 id="item-1-2">Item 2-2</h5>
  <p>...</p>
  <h4 id="item-2">Item 2</h4>
  <p>...</p>
  <h4 id="item-3">Item 3</h4>
  <p>...</p>
  <h5 id="item-3-1">Item 3-1</h5>
  <p>...</p>
  <h5 id="item-3-2">Item 3-2</h5>
  <p>...</p>
</div>

Misali ni list-group ye

Scrollspy fana bɛ baara kɛ ni .list-groups ye. Yɔrɔ min bɛ lisi kulu kɛrɛfɛ, i ka o yɔrɔ lajɛ ani ka kalansen caman yeli lajɛ min bɛ baara la.

Fɛn 1nan

Ex consequat commodo adipisicing farikoloɲɛnajɛ aute excepteur occaecat ullamco duis aliqua id magna ullamco eu. Aw bɛ aute ipsum ipsum ullamco cillum consectetur kɛ ani ka aute consectetur baara kɛ. Fugiat laborum incididunt tempor eu kɔlɔlɔ ye enim dolore proident ye. Qui laborum do non excepteur nulla magna eiusmod consectetur in. Aliqua et aliqua officia quis et incididunt voluptate non anim reprehenderit farali dolore ut consequat deserunt mollit dolore. Aliquip nulla enim veniam non fugiat id cupidat nulla elit kupidat commodo velit ut eiusmod kupidata elit dolore.

Fɛn 2nan

Quis magna Lorem ani amet ipsum do mollit sigi cillum voluptate ex nulla tempor. Laborum consequat non elit enim farikoloɲɛnajɛ cillum aliqua kɔlɔlɔ id aliqua. Esse ex consectetur mollit voluptate est in duis laboris ka baara kɛ ni ipsum ani Lorem ye. Incididunt veniam velit elit elit veniam Lorem ye fɛn ye min bɛ se ka kɛ fɛn ye min bɛ se ka kɛ fɛn ye min bɛ se ka kɛ fɛn ye. Laborum nisi sit est tempor laborum mollit labore officia baara min tɛ kɛ ni fɛn ye min tɛ fɛn ye min tɛ fɛn ye min tɛ fɛn ye min tɛ fɛn ye min tɛ fɛn ye min tɛ fɛn ye min tɛ fɛn ye min tɛ fɛn ye. Ipsum fugiat ex est consectetur ipsum commodo waatilama sunt in proident.

Fɛn 3nan

Quis ani sigi do amet fugiat dolor velit sigi ea ea do reprehenderit culpa duis. Nostrud aliqua ipsum fugiat minim proident occaecat excepteur aliquip culpa aute tempor ka jalaki. Deserunt tempor mollit elit ex pariatur dolore velit fugiat culpa irure ullamco est ex ullamco excepteur.

Fɛn 4nan

Quis ani sigi do amet fugiat dolor velit sigi ea ea do reprehenderit culpa duis. Nostrud aliqua ipsum fugiat minim proident occaecat excepteur aliquip culpa aute tempor ka jalaki. Deserunt tempor mollit elit ex pariatur dolore velit fugiat culpa irure ullamco est ex ullamco excepteur.

<div id="list-example" class="list-group">
  <a class="list-group-item list-group-item-action" href="#list-item-1">Item 1</a>
  <a class="list-group-item list-group-item-action" href="#list-item-2">Item 2</a>
  <a class="list-group-item list-group-item-action" href="#list-item-3">Item 3</a>
  <a class="list-group-item list-group-item-action" href="#list-item-4">Item 4</a>
</div>
<div data-spy="scroll" data-target="#list-example" data-offset="0" class="scrollspy-example">
  <h4 id="list-item-1">Item 1</h4>
  <p>...</p>
  <h4 id="list-item-2">Item 2</h4>
  <p>...</p>
  <h4 id="list-item-3">Item 3</h4>
  <p>...</p>
  <h4 id="list-item-4">Item 4</h4>
  <p>...</p>
</div>

Baarakɛcogo

Donanw ka fɛnɲɛnɛmaw fɛ

Walasa ka scrollspy kɛcogo fara nɔgɔya la i ka topbar navigation kan, data-spy="scroll"i b’a fɛ ka spy min kɛ, i ka fara o kan (a ka c’a la nin bɛna kɛ <body>). O kɔ fɛ, i bɛ fɛn in Fàra a kan data-targetni Bootstrap .navyɔrɔ o yɔrɔ bangebaga-yɔrɔ ID walima a kalasi ye.

body {
  position: relative;
}
<body data-spy="scroll" data-target="#navbar-example">
  ...
  <div id="navbar-example">
    <ul class="nav nav-tabs" role="tablist">
      ...
    </ul>
  </div>
  ...
</body>

JavaScript fɛ

I kɛlen kɔ ka fara position: relative;i ka CSS kan, i ka scrollspy wele JavaScript fɛ:

$('body').scrollspy({ target: '#navbar-example' })

ID laɲiniw minnu bɛ se ka ɲɛnabɔ, olu wajibiyalen don

Navbar jɛgɛnw ka kan ka kɛ ni id laɲiniw ye minnu bɛ se ka ɲɛnabɔ. Misali la, a <a href="#home">home</a>ka kan ka bɛn fɛn dɔ ma DOM kɔnɔ i n’a fɔ <div id="home"></div>.

Fɛn minnu tɛ :visiblelaɲini ye, olu ma jate

Laɲinifɛnw minnu tɛ :visibleka kɛɲɛ ni jQuery ye , olu bɛna jate ani u nav fɛnw bɛnninw tɛna jira abada.

Fɛɛrɛw

.scrollspy('refresh')

Ni i bɛ baara kɛ ni scrollspy ye ka fara fɛnw farali walima u bɔli kan DOM kɔnɔ, i bɛna a ɲini ka refresh fɛɛrɛ wele i n’a fɔ:

$('[data-spy="scroll"]').each(function () {
  var $spy = $(this).scrollspy('refresh')
})

.scrollspy('dispose')

A bɛ element dɔ ka scrollspy tiɲɛ.

Sugandili minnu bɛ kɛ

Sugandili bɛ se ka tɛmɛ data attributes walima JavaScript fɛ. Donanw cogoyaw kama, aw bɛ sugandi tɔgɔ fara data-, i n’a fɔ a bɛ cogo min na data-offset="".

Tɔ̀gɔ Ka sɛbɛen masin na Fɔlɔ Cogojirali
offset (fɔcogo ɲuman). nimɔrɔ 10 ye Pixels ka offset ka bɔ sanfɛ ni jatebɔ jɔyɔrɔ scroll.

Ko minnu kɛra

Ko kɛlen suguya Cogojirali
ka baara kɛ.bs.scrollspy ye O ko in bɛ tasuma Bɔ sɛbɛnfura yɔrɔ la tuma o tuma ni fɛn kura dɔ Kɛra baara la sɛbɛnfura fɛ.
$('[data-spy="scroll"]').on('activate.bs.scrollspy', function () {
  // do something…
})