1 | # Sticky Sidebar [](https://travis-ci.org/abouolia/sticky-sidebar)
|
2 |
|
3 | Pure JavaScript plugin for making smart and high performance sticky sidebars.
|
4 |
|
5 | [Basic Example](https://abouolia.github.io/sticky-sidebar/examples/basic.html)
|
6 |
|
7 | [Scrollable Sticky Element](https://abouolia.github.io/sticky-sidebar/examples/scrollable-element.html)
|
8 |
|
9 | See for complete documentation and examples [abouolia.github.com/sticky-sidebar](http://abouolia.github.com/sticky-sidebar)
|
10 |
|
11 | ## Why sticky sidebar is awesome?
|
12 |
|
13 | * It does not re-calculate all dimensions when scrolling, just neccessary dimensions.
|
14 | * Super smooth without incurring scroll lag or jank and no page reflows.
|
15 | * Integrated with resize sensor to re-calculate all dimenstions of the plugin when size of sidebar or its container is changed.
|
16 | * It has event trigger on each affix type to hook your code under particular situation.
|
17 | * Handle the sidebar when is tall or too short compared to the rest of the container.
|
18 | * Zero dependencies and super simple to setup.
|
19 |
|
20 | ## Install
|
21 |
|
22 | You can download sticky sidebar jquery plugin from Bowser, NPM or just simply download it from here than put ``sticky-sidebar.js`` file in your project folder.
|
23 |
|
24 | #### Bower
|
25 |
|
26 | If you are using bower as package manager:
|
27 |
|
28 | ````
|
29 | bower install sticky-sidebar
|
30 | ````
|
31 |
|
32 | #### NPM
|
33 |
|
34 | If you are using NPM as package manager:
|
35 |
|
36 | ````
|
37 | npm install sticky-sidebar
|
38 | ````
|
39 |
|
40 | ## Usage
|
41 |
|
42 | Your website's html structure has to be similer to this in order to work:
|
43 |
|
44 | ````html
|
45 | <div class="main-content">
|
46 | <div class="sidebar">
|
47 | <div class="sidebar__inner">
|
48 | <!-- Content goes here -->
|
49 | </div>
|
50 | </div>
|
51 | <div class="content">
|
52 | <!-- Content goes here -->
|
53 | </div>
|
54 | </div>
|
55 | ````
|
56 |
|
57 | Note that inner sidebar wrapper ``.sidebar__innner`` is optional but highly recommended, if you don't write it yourself, the script will create one for you under class name ``inner-wrapper-sticky``. but this may cause many problems.
|
58 |
|
59 | For the above example, you can use the following JavaScript:
|
60 |
|
61 | ````html
|
62 | <script type="text/javascript" src="./js/sticky-sidebar.js"></script>
|
63 |
|
64 | <script type="text/javascript">
|
65 | var sidebar = new StickySidebar('.sidebar', {
|
66 | topSpacing: 20,
|
67 | bottomSpacing: 20,
|
68 | containerSelector: '.main-content',
|
69 | innerWrapperSelector: '.sidebar__inner'
|
70 | });
|
71 | </script>
|
72 | ````
|
73 |
|
74 | #### Via jQuery/Zepto
|
75 |
|
76 | You can configure sticky sidebar as a jQuery plugin, just include ``jquery.sticky-sidebar.js`` instead ``sticky-sidebar.js`` file than configure it as any jQuery plugin.
|
77 |
|
78 | ````html
|
79 | <script type="text/javascript" src="./js/jquery.js"></script>
|
80 | <script type="text/javascript" src="./js/jquery.sticky-sidebar.js"></script>
|
81 |
|
82 | <script type="text/javascript">
|
83 | $('#sidebar').stickySidebar({
|
84 | topSpacing: 60,
|
85 | bottomSpacing: 60
|
86 | });
|
87 | </script>
|
88 | ````
|
89 |
|
90 | Make sure to include ``sticky-sidebar.js`` script file after ``jquery.js``.
|
91 |
|
92 | ## Usage with [ResizeSensor.js](https://github.com/marcj/css-element-queries/blob/master/src/ResizeSensor.js)
|
93 |
|
94 | Sticky sidebar integrated with [ResizeSensor.js](https://github.com/marcj/css-element-queries/blob/master/src/ResizeSensor.js) to detect when sidebar or container is changed. To use resize sensor with this plugin just make sure to include ResizeSensor.js before `sticky-sidebar.js` code whether through module loader, bundle or event inclusion as a `<script>` and enable `resizeSensor` option (enabled by default) and it will works.
|
95 |
|
96 | You can choose not to include `ResizeSensor.js` and sticky sidebar will continue work without any problem but without automatically detect resize changes.
|
97 |
|
98 | ## Broswers Support
|
99 |
|
100 | Sticky sidebar works in all modern browsers including Internet Explorer 9 and above, but if you want it to work with IE9, should include [`requestAnimationFrame`](https://gist.github.com/paulirish/1579671) polyfill before sticky sidebar code.
|
101 |
|
102 | If you have any issue with browser compatibility don’t hesitate to [Submit an issue](https://github.com/abouolia/sticky-sidebar/issues/new).
|
103 |
|
104 | ## License
|
105 |
|
106 | Sticky Sidebar is released under the MIT license. Have at it.
|
107 |
|
108 | -------
|
109 |
|
110 | Made by Ahmed Bouhuolia
|
111 |
|
\ | No newline at end of file |