Permalink
Browse files

Version 0.5.0

  • Loading branch information...
bbarakaci committed Jun 16, 2016
1 parent 2151380 commit 2ef69350091d4dadc9f170a8496cba64f07aa73c
Showing with 28 additions and 19 deletions.
  1. +4 −0 README.md
  2. +20 −15 dist/fixto.js
  3. +2 −2 dist/fixto.min.js
  4. +1 −1 grunt.js
  5. +1 −1 package.json
View
@@ -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
View
@@ -1,4 +1,4 @@
-/*! fixto - v0.4.0 - 2015-06-08
+/*! fixto - v0.5.0 - 2016-06-16
* http://github.com/bbarakaci/fixto/*/
@@ -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);
}
@@ -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();
@@ -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();
Oops, something went wrong.

0 comments on commit 2ef6935

Please sign in to comment.