├── .babelrc ├── .gitignore ├── .travis.yml ├── Gulpfile.js ├── LICENSE.md ├── README.md ├── bower.json ├── dist ├── jquery.sticky-sidebar.js ├── jquery.sticky-sidebar.js.map ├── jquery.sticky-sidebar.min.js ├── sticky-sidebar.js ├── sticky-sidebar.js.map └── sticky-sidebar.min.js ├── package.json ├── src ├── jquery.sticky-sidebar.js └── sticky-sidebar.js └── test ├── index.html ├── mockraf.js └── test.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | "transform-es2015-modules-umd", 4 | "check-es2015-constants", 5 | "transform-es2015-block-scoped-functions", 6 | "transform-es2015-arrow-functions", 7 | "transform-es2015-classes", 8 | "transform-es2015-parameters", 9 | "transform-es2015-block-scoping", 10 | "transform-export-extensions" 11 | ] 12 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | /node_modules/ 3 | /bower_components/ 4 | docs/_site 5 | docs/.sass-cache 6 | 7 | /dist/ -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false, 2 | 3 | language: node_js 4 | 5 | node_js: 6 | - 6 7 | 8 | before_install: 9 | - npm install -g bower 10 | 11 | install: 12 | - npm install 13 | - bower install 14 | 15 | script: 16 | - gulp -------------------------------------------------------------------------------- /Gulpfile.js: -------------------------------------------------------------------------------- 1 | 2 | const gulp = require("gulp"); 3 | const sourcemaps = require("gulp-sourcemaps"); 4 | const babel = require("gulp-babel"); 5 | const uglify = require('gulp-uglify'); 6 | const rename = require('gulp-rename'); 7 | const header = require('gulp-header'); 8 | const gutil = require('gulp-util'); 9 | const rollup = require('gulp-rollup'); 10 | const resolve = require('rollup-plugin-node-resolve'); 11 | const commonjs = require('rollup-plugin-commonjs'); 12 | const pkg = require('./package.json'); 13 | 14 | const banner = [ 15 | '/**', 16 | ' * <%= pkg.name %> - <%= pkg.description %>', 17 | ' * @version v<%= pkg.version %>', 18 | ' * @link <%= pkg.homepage %>', 19 | ' * @author <%= pkg.author %>', 20 | ' * @license <%= pkg.license %>', 21 | '**/', 22 | '', 23 | ].join('\n'); 24 | 25 | gulp.task("babel", function(){ 26 | return gulp.src("src/*.js") 27 | .pipe(babel()) 28 | .pipe(gulp.dest("dist")); 29 | }); 30 | 31 | gulp.task('bundle', ['babel'], function(){ 32 | return gulp.src(["dist/sticky-sidebar.js", "dist/jquery.sticky-sidebar.js"]) 33 | .pipe(sourcemaps.init()) 34 | // transform the files here. 35 | .pipe(rollup({ 36 | allowRealFiles: true, 37 | // any option supported by Rollup can be set here. 38 | input: ['./dist/sticky-sidebar.js', './dist/jquery.sticky-sidebar.js'], 39 | format: 'umd', 40 | name: 'StickySidebar', 41 | plugins: [ resolve(), commonjs() ] 42 | })) 43 | .pipe(sourcemaps.write('.')) 44 | .pipe(gulp.dest('./dist')); 45 | }); 46 | 47 | gulp.task('uglify', ['bundle'], function(){ 48 | return gulp.src(["dist/sticky-sidebar.js", "dist/jquery.sticky-sidebar.js"]) 49 | .pipe(uglify()) 50 | .on('error', function (err) { gutil.log(gutil.colors.red('[Error]'), err.toString()); }) 51 | .pipe(header(banner, {pkg})) 52 | .pipe(rename({ suffix: '.min' })) 53 | .pipe(gulp.dest("dist/")); 54 | }); 55 | 56 | gulp.task('watch', function() { 57 | gulp.watch('src/*.js', ['default']); 58 | }); 59 | 60 | gulp.task('default', ['babel', 'bundle', 'uglify']); -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2017 Ahmed Bouhuolia 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 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 | For complete documentation and examples see [abouolia.github.com/sticky-sidebar](http://abouolia.github.com/sticky-sidebar) 10 | 11 | ## Why is sticky sidebar so awesome? 12 | 13 | * It does not re-calculate all dimensions when scrolling, just necessary 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 this page and link to the ``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 similar to this in order to work: 43 | 44 | ````html 45 |