- Overview
- Documents
Features
- determining which section on the page (or inside a custom scrollable element) is currently active
- many options, including multiple modes of resolution (visible height, focus line, custom, none)
- mapping the active section to an "active class" on some list of elements (e.g. menu items)
Browser support
Tested in Mozilla Firefox, Google Chrome, Safari, Opera and MSIE 7+.
sex shop sex shop sex shop sex shop sex shop seks shop spanish fly psikolog sohbet numara sohbet hatti
Source: github.com
1. INCLUDE JS FILES
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script> <script type="text/javascript" src="src/scrollwatch.js"></script>
2. HTML
<div id="scrollable"> <ul class="menu"> <li><a href="#scrollable_1">1</a></li> <li><a href="#scrollable_2">2</a></li> <li><a href="#scrollable_3">3</a></li> <li><a href="#scrollable_4">4</a></li> <li><a href="#scrollable_5">5</a></li> </ul> <div> <div id="scrollable_1">1</div> <div id="scrollable_2">2</div> <div id="scrollable_3">3</div> <div id="scrollable_4">4</div> <div id="scrollable_5">5</div> </div> </div>
3. JAVASCRIPT
$('#scrollable > div > div').scrollWatchMapTo('#scrollable > ul.menu > li');
4. METHODS
The plugin provides two jQuery methods you can use:
$(sections).scrollWatch(callback[, options])
Attaches a watcher to the given sections. The callback is then invoked when the focus changes, according to options.
- sections - selector or an array of elements that represent all the possible sections
- callback - function to invoke when the focus changes
- options - object with various settings (see list far below)
Returns: an instance of Shira.ScrollWatch.Watcher or false if no sections were given / matched.
Callback arguments
-
0 - the current focus, an object with the following keys (if resolutionMode is none, it will be an array of those objects):
- index - section number (0 based)
- intersection - null or an array with top coordinate as element 0 and bottom coordinate as element 1
- section - DOM element of the section
-
1 - the current view, an object with the following keys:
- top - top coordinate of the view
- bottom - bottom coordinate of the view
- 2 - an instance of Shira.ScrollWatch.Watcher
Example:
$(document).ready(function () { $('div.section').scrollWatch(function (focus) { console.log(focus); }); });
$(sections).scrollWatchMapTo(items[, activeClass, options])
Attaches a watcher to the given sections and maps the current focus as an "active class" to the respective item.
- sections - selector or an array of elements that represent all the possible sections
- items - selector or an array of elements to map the "active class" to
- activeClass - class name to add to the active item (defaults to "active")
- options - object with various settings (see list far below)
Returns: an instance of Shira.ScrollWatch.Watcher or false if no sections were given / matched.
Example:
$(document).ready(function () { $('div.section').scrollWatchMapTo('#menu > li'); });
5. OPTIONS
List of all available options.
Name | Default | Description |
---|---|---|
scroller | null | DOM element to watch for scrolling events (window or element with position: relative or absolute). If no element is given, window or first section's offset parent will be used instead. |
resolutionMode | "height" |
Determines how the active section is chosen:
|
viewMarginTop | 0 | Height of an area at the top of the view to be excluded. |
viewMarginBottom | 0 | Height of an area at the bottom of the view to be excluded. |
stickyOffsetTop | 5 | Height of an area at the top of the scroller that, if intersected by the top of the view, forces the first section to be active regardless of other conditions. |
stickyOffsetBottom | 5 | Height of an area at the bottom of the scroller that, if intersected by the bottom of the view, forces the last section to be active regardless of other conditions. |
throttle | true | When enabled, the callback is invoked only when the active section changes. When disabled, the callback is invoked on every pulse (e.g. on scroll, resize). This has no effect whenresolutionMode is none. |
Options specific to resolutionMode = "height"
Name | Default | Description |
---|---|---|
topDownWeight | 0 | Extra focus height added to the section if it precedes the other. This can be used to prefer earlier sections to later ones. |
Options specific to resolutionMode = "focus-line"
Name | Default | Description |
---|---|---|
focusRatio | 0.3819.. | Percentage of the view height that determines position of the focus line. |
focusOffset | 0 | Offset added to position of the focus line position afterfocusRatio is applied. (Set focusRatio to 0 if you wish to use the focusOffset as an absolute value). |
debugFocusLine | false | When enabled, position of the focus line will be displayed when scrolling (for debugging purposes). |
Options specific to resolutionMode = "custom"
Name | Default | Description |
---|---|---|
resolver | required |
Function to invoke when a resolution is needed. It must choose and returna single focus object. The following arguments are passed to it:
|