Bs Affix

Bootstrap Affix Plugin (Advanced)


The Affix Plugin

The Affix plugin allows an chemical gene to teach affixed (locked) to an expanse on the page. This is oft used amongst navigation menus or social ikon buttons, to brand them "stick" at a specific expanse spell scrolling upward as well as downward the page.
The plugin toggles this demeanor on as well as off (changes the value of CSS position from static to fixed), depending on scroll position.
Example 1) An affixed navbar:
Example 2) An affixed sidebar:
With Affix, when nosotros scroll upward as well as downward the page, the bill of fare is ever visible as well as locked inwards its position.

How To Create an Affixed Navigation Menu

The next instance shows how to exercise a horizontal affixed navigation menu:

Example

<nav class="navbar navbar-inverse" data-spy="affix" data-offset-top="197">
The next instance shows how to exercise a vertical affixed navigation menu:

Example

<ul class="nav nav-pills nav-stacked" data-spy="affix" data-offset-top="205">

Example Explained

Add data-spy="affix" to the chemical gene you lot desire affixed.
Optionally, add together the data-offset-top|bottom attribute to calculate the grade of the scroll.

How it works

The affix plugin toggles betwixt 3 classes: .affix, .affix-top, as well as .affix-bottom. Each cast represents a item state. You must add together CSS properties to grip the actual positions, amongst the exception of position:fixed on the .affix class.
  • The plugin adds the .affix-top or .affix-bottom cast to signal the chemical gene is inwards its top-most or bottom-most position. Positioning amongst CSS is non required at this point.

  • Scrolling by the affixed chemical gene triggers the actual affixing - This is where the plugin replaces the .affix-top or .affix-bottom cast amongst the .affix cast (sets position:fixed). At this point, you lot must add together the CSS top or bottom holding to grade the affixed chemical gene inwards the page.

  • If a bottom offset is defined, scrolling by it replaces the .affix cast amongst .affix-bottom. Since offsets are optional, setting ane requires you lot to laid the appropriate CSS. In this case, add together position:absolute when necessary.
In the kickoff instance above, the Affix plugin adds the .affix cast (position:fixed) to the <nav> chemical gene when nosotros convey scrolled 197 pixels from the top. If you lot opened upward the example, you lot volition besides come across that nosotros added the CSS top holding amongst a value of 0 to the .affix class. This is to brand certain that the navbar stays at the pinnacle of the page at all time, when nosotros convey scrolled 197 pixels from the top.

Scrollspy & Affix

Using the Affix plugin together amongst the Scrollspy plugin:

Horizontal Menu (Navbar)

<body data-spy="scroll" data-target=".navbar" data-offset="50">

<nav class="navbar navbar-inverse" data-spy="affix" data-offset-top="197">
...
</nav>

</body>

Vertical Menu (Sidenav)

<body data-spy="scroll" data-target="#myScrollspy" data-offset="15">

<nav class="col-sm-3" id="myScrollspy">
  <ul class="nav nav-pills nav-stacked" data-spy="affix" data-offset-top="205">
  ...
</nav>

</body>


Comments

Popular posts from this blog

What Are The Main Components of a Computer System

Top Qualities To Look For In An IT Support Team

How To Integrate Google Adwords Api Into Codeigniter?