Last active
September 8, 2015 15:35
-
-
Save Craga89/b35f8bbe83e8e0e7a2a7 to your computer and use it in GitHub Desktop.
Tether.js - Transition small movements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.tether.tether-transition { | |
transition: -webkit-transform 100ms ease-in-out; | |
transition: transform 100ms ease-in-out; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var transitionModule = { | |
className: 'transition', | |
thresholdX: 50, | |
thresholdY: 50, | |
position: function(props) { | |
var className = this.options.classPrefix + '-' + transitionModule.className, | |
hasClass = Tether.Utils.hasClass(this.element, className), | |
lastOffset = this._cacheOffset; | |
var shouldAddClass = lastOffset && | |
Math.abs(props.left - lastOffset[0]) <= transitionModule.thresholdX && | |
Math.abs(props.top - lastOffset[1]) <= transitionModule.thresholdY; | |
if(!hasClass && shouldAddClass) { | |
Tether.Utils.addClass(this.element, className); | |
} | |
else if(hasClass && !shouldAddClass) { | |
Tether.Utils.removeClass(this.element, className); | |
} | |
// Cache the offset | |
this._cacheOffset = [props.left, props.top]; | |
} | |
}; | |
Tether.modules.push(transitionModule); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment