Skip to content

Commit

Permalink
Version 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bbarakaci committed Jun 16, 2016
1 parent 2151380 commit 2ef6935
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ jQuery:
Or we will choose the other path. We will decide to implement the features we need to have fixto as a plugin that does its own magic. Please open an issue if you would like to see additional features when running on native sticky mode. If there is an issue, just participate with your +1. It will help us to decide for the future.

## Release notes
### 0.5.0
- Sensitivity to the viewport is now an optional feature.
- Added MIT license.

### 0.4.0
- Added "mindBottomPadding" option, to make including parent's bottom padding optional when calculating max bottom position of the fixed element

Expand Down
35 changes: 20 additions & 15 deletions dist/fixto.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! fixto - v0.4.0 - 2015-06-08
/*! fixto - v0.5.0 - 2016-06-16
* http://github.com/bbarakaci/fixto/*/


Expand Down Expand Up @@ -303,7 +303,8 @@ var fixto = (function ($, window, document) {
this.parent = parent;
this.options = {
className: 'fixto-fixed',
top: 0
top: 0,
mindViewport: false
};
this._setOptions(options);
}
Expand Down Expand Up @@ -437,19 +438,9 @@ var fixto = (function ($, window, document) {
this._parentBottom -= computedStyle.getFloat(this.parent, 'paddingBottom');
}

if (!this.fixed) {

var childStyles = computedStyle.getAll(this.child);

if (
this._scrollTop < this._parentBottom &&
this._scrollTop > (this._fullOffset('offsetTop', this.child) - this.options.top - this._mindtop()) &&
this._viewportHeight > (this.child.offsetHeight + computedStyle.toFloat(childStyles.marginTop) + computedStyle.toFloat(childStyles.marginBottom))
) {

this._fix();
this._adjust();
}
if (!this.fixed && this._shouldFix()) {
this._fix();
this._adjust();
} else {
if (this._scrollTop > this._parentBottom || this._scrollTop < (this._fullOffset('offsetTop', this._ghostNode) - this.options.top - this._mindtop())) {
this._unfix();
Expand All @@ -459,6 +450,20 @@ var fixto = (function ($, window, document) {
}
},

_shouldFix: function() {
if (this._scrollTop < this._parentBottom && this._scrollTop > (this._fullOffset('offsetTop', this.child) - this.options.top - this._mindtop())) {
if (this.options.mindViewport && !this._isViewportAvailable()) {
return false;
}
return true;
}
},

_isViewportAvailable: function() {
var childStyles = computedStyle.getAll(this.child);
return this._viewportHeight > (this.child.offsetHeight + computedStyle.toFloat(childStyles.marginTop) + computedStyle.toFloat(childStyles.marginBottom));
},

_adjust: function _adjust() {
var top = 0;
var mindTop = this._mindtop();
Expand Down
Loading

0 comments on commit 2ef6935

Please sign in to comment.