Skip to content
This repository has been archived by the owner on Jan 11, 2022. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rgalus committed Dec 6, 2016
2 parents 540f33b + 91bc585 commit 891593b
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Sticky-js is a library for sticky elements written in vanilla javascript. With t
## Features

- Written in vanilla javascript, no dependencies needed
- Lightweight (minified: ~5.12kb, gzipped: ~1.45kb)
- Lightweight (minified: ~5.28kb, gzipped: ~1.48kb)
- It can be sticky to the entire page or to selected parent container
- No additional CSS needed

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
"test",
"tests"
],
"version": "1.1.5"
"version": "1.1.6"
}
17 changes: 11 additions & 6 deletions dist/sticky.compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
* Sticky.js
* Library for sticky elements written in vanilla javascript. With this library you can easily set sticky elements on your website. It's also responsive.
*
* @version 1.1.5
* @version 1.1.6
* @author Rafal Galus <[email protected]>
* @website https://rgalus.github.io/sticky-js/
* @repo https://github.com/rgalus/sticky-js
Expand All @@ -27,15 +27,17 @@ var Sticky = function () {
this.selector = selector;
this.elements = [];

this.version = '1.1.5';
this.version = '1.1.6';

this.vp = this.getViewportSize();
this.scrollTop = this.getScrollTopPosition();
this.body = document.querySelector('body');

this.options = {
marginTop: options.marginTop || 0,
stickyFor: options.stickFor || 0,
stickyClass: options.stickyClass || null
stickyClass: options.stickyClass || null,
stickyContainer: options.stickyContainer || 'body'
};

this.run();
Expand Down Expand Up @@ -82,6 +84,9 @@ var Sticky = function () {
element.sticky.marginTop = parseInt(element.getAttribute('data-margin-top')) || this.options.marginTop;
element.sticky.stickyFor = parseInt(element.getAttribute('data-sticky-for')) || this.options.stickyFor;
element.sticky.stickyClass = element.getAttribute('data-sticky-class') || this.options.stickyClass;
// @todo attribute for stickyContainer
// element.sticky.stickyContainer = element.getAttribute('data-sticky-container') || this.options.stickyContainer;
element.sticky.stickyContainer = this.options.stickyContainer;

element.sticky.container = this.getStickyContainer(element);
element.sticky.container.rect = this.getRectangle(element.sticky.container);
Expand Down Expand Up @@ -215,7 +220,7 @@ var Sticky = function () {
element.sticky.rect = this.getRectangle(element);
}

if (element.sticky.rect.top === 0 && element.sticky.container === document.querySelector('body')) {
if (element.sticky.rect.top === 0 && element.sticky.container === this.body) {
this.css(element, {
position: 'fixed',
top: element.sticky.rect.top + 'px',
Expand Down Expand Up @@ -274,9 +279,9 @@ var Sticky = function () {


Sticky.prototype.getStickyContainer = function getStickyContainer(element) {
var container = element;
var container = element.parentNode;

while (!container.hasAttribute('data-sticky-container') && container !== document.querySelector('body')) {
while (!container.hasAttribute('data-sticky-container') && !container.parentNode.querySelector(element.sticky.stickyContainer) && container !== this.body) {
container = container.parentNode;
}

Expand Down
2 changes: 1 addition & 1 deletion dist/sticky.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified dist/sticky.min.js.gz
Binary file not shown.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sticky-js",
"version": "1.1.5",
"version": "1.1.6",
"description": "Sticky elements",
"main": "index.js",
"scripts": {
Expand All @@ -25,10 +25,10 @@
},
"homepage": "https://github.com/rgalus/sticky-js#readme",
"devDependencies": {
"babel-core": "^6.14.0",
"babel-preset-es2015": "^6.14.0",
"babel-register": "^6.14.0",
"browser-sync": "^2.15.0",
"babel-core": "^6.18.2",
"babel-preset-es2015": "^6.18.0",
"babel-register": "^6.18.0",
"browser-sync": "^2.18.2",
"del": "^2.2.2",
"gulp": "github:gulpjs/gulp#4.0",
"gulp-babel": "^6.1.2",
Expand Down
16 changes: 11 additions & 5 deletions src/sticky.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Sticky.js
* Library for sticky elements written in vanilla javascript. With this library you can easily set sticky elements on your website. It's also responsive.
*
* @version 1.1.5
* @version 1.1.6
* @author Rafal Galus <[email protected]>
* @website https://rgalus.github.io/sticky-js/
* @repo https://github.com/rgalus/sticky-js
Expand All @@ -21,15 +21,17 @@ class Sticky {
this.selector = selector;
this.elements = [];

this.version = '1.1.5';
this.version = '1.1.6';

this.vp = this.getViewportSize();
this.scrollTop = this.getScrollTopPosition();
this.body = document.querySelector('body');

this.options = {
marginTop: options.marginTop || 0,
stickyFor: options.stickFor || 0,
stickyClass: options.stickyClass || null,
stickyContainer: options.stickyContainer || 'body',
};

this.run();
Expand Down Expand Up @@ -68,6 +70,9 @@ class Sticky {
element.sticky.marginTop = parseInt(element.getAttribute('data-margin-top')) || this.options.marginTop;
element.sticky.stickyFor = parseInt(element.getAttribute('data-sticky-for')) || this.options.stickyFor;
element.sticky.stickyClass = element.getAttribute('data-sticky-class') || this.options.stickyClass;
// @todo attribute for stickyContainer
// element.sticky.stickyContainer = element.getAttribute('data-sticky-container') || this.options.stickyContainer;
element.sticky.stickyContainer = this.options.stickyContainer;

element.sticky.container = this.getStickyContainer(element);
element.sticky.container.rect = this.getRectangle(element.sticky.container);
Expand Down Expand Up @@ -200,7 +205,7 @@ class Sticky {

if (
element.sticky.rect.top === 0
&& element.sticky.container === document.querySelector('body')
&& element.sticky.container === this.body
) {
this.css(element, {
position: 'fixed',
Expand Down Expand Up @@ -260,11 +265,12 @@ class Sticky {
* @return {node} element - Sticky container
*/
getStickyContainer(element) {
let container = element;
let container = element.parentNode;

while (
!container.hasAttribute('data-sticky-container')
&& container !== document.querySelector('body')
&& !container.parentNode.querySelector(element.sticky.stickyContainer)
&& container !== this.body
) {
container = container.parentNode;
}
Expand Down

0 comments on commit 891593b

Please sign in to comment.