Skip to content

Instantly share code, notes, and snippets.

@Craga89
Last active September 8, 2015 15:35
Show Gist options
  • Save Craga89/b35f8bbe83e8e0e7a2a7 to your computer and use it in GitHub Desktop.
Save Craga89/b35f8bbe83e8e0e7a2a7 to your computer and use it in GitHub Desktop.
Tether.js - Transition small movements
.tether.tether-transition {
transition: -webkit-transform 100ms ease-in-out;
transition: transform 100ms ease-in-out;
}
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