{
const config = {
in: {
base: {
duration: 400,
easing: 'easeOutQuint',
scaleX: [1.2,1],
opacity: {
value: 1,
easing: 'linear',
duration: 50
}
},
path: {
duration: 600,
easing: 'easeOutQuint',
d: 'M 92.4,79 C 136,79 156,79.1 200,79.4 244,79.7 262,79 308,79 354,79 381,111 381,150 381,189 346,220 308,221 270,222 236,221 200,221 164,221 130,222 92.4,221 54.4,220 19,189 19,150 19,111 48.6,79 92.4,79 Z'
},
content: {
delay: 100,
scale: {
value: [0.8,1],
duration: 300,
easing: 'easeOutQuint'
},
opacity: {
value: [0,1],
easing: 'linear',
duration: 100
}
},
trigger: {
duration: 300,
easing: 'easeOutQuint',
scale: [1,0.9],
color: '#6fbb95'
}
},
out: {
base: {
duration: 200,
easing: 'easeInQuint',
scaleX: 1.1,
scaleY: 0.9,
opacity: {
value: 0,
delay: 100,
duration: 150,
easing: 'linear'
}
},
path: {
duration: 200,
easing: 'easeInQuint',
d: 'M 92.4,79 C 136,79 154,115 200,116 246,117 263,80.4 308,79 353,77.6 381,111 381,150 381,189 346,220 308,221 270,222 236,188 200,188 164,188 130,222 92.4,221 54.4,220 19,189 19,150 19,111 48.6,79 92.4,79 Z'
},
content: {
duration: 150,
easing: 'easeInQuint',
scale: 0.8,
opacity: {
value: 0,
duration: 100,
easing: 'linear'
}
},
trigger: {
duration: 200,
easing: 'easeInQuint',
scale: 1,
color: '#666'
}
}
};
const tooltip = document.querySelector('.tooltip');
class Tooltip {
constructor(el) {
this.DOM = {};
this.DOM.el = el;
this.DOM.trigger = this.DOM.el.querySelector('.tooltip__trigger');
this.DOM.triggerSpan = this.DOM.el.querySelector('.tooltip__trigger-text');
this.DOM.base = this.DOM.el.querySelector('.tooltip__base');
this.DOM.shape = this.DOM.base.querySelector('.tooltip__shape');
if( this.DOM.shape ) {
this.DOM.path = this.DOM.shape.childElementCount > 1 ? Array.from(this.DOM.shape.querySelectorAll('path')) : this.DOM.shape.querySelector('path');
}
this.DOM.deco = this.DOM.base.querySelector('.tooltip__deco');
this.DOM.content = this.DOM.base.querySelector('.tooltip__content');
this.DOM.letters = this.DOM.content.querySelector('.tooltip__letters');
if( this.DOM.letters ) {
// Create spans for each letter.
charming(this.DOM.letters);
// Redefine content.
this.DOM.content = this.DOM.letters.querySelectorAll('span');
}
this.initEvents();
}
initEvents() {
this.mouseenterFn = () => {
this.mouseTimeout = setTimeout(() => {
this.isShown = true;
this.show();
}, 75);
}
this.mouseleaveFn = () => {
clearTimeout(this.mouseTimeout);
if( this.isShown ) {
this.isShown = false;
this.hide();
}
}
this.DOM.trigger.addEventListener('mouseenter', this.mouseenterFn);
this.DOM.trigger.addEventListener('mouseleave', this.mouseleaveFn);
this.DOM.trigger.addEventListener('touchstart', this.mouseenterFn);
this.DOM.trigger.addEventListener('touchend', this.mouseleaveFn);
}
show() {
this.animate('in');
}
hide() {
this.animate('out');
}
animate(dir) {
if ( config[dir].base ) {
anime.remove(this.DOM.base);
let baseAnimOpts = {targets: this.DOM.base};
anime(Object.assign(baseAnimOpts, config[dir].base));
}
if ( config[dir].shape ) {
anime.remove(this.DOM.shape);
let shapeAnimOpts = {targets: this.DOM.shape};
anime(Object.assign(shapeAnimOpts, config[dir].shape));
}
if ( config[dir].path ) {
anime.remove(this.DOM.path);
let shapeAnimOpts = {targets: this.DOM.path};
anime(Object.assign(shapeAnimOpts, config[dir].path));
}
if ( config[dir].content ) {
anime.remove(this.DOM.content);
let contentAnimOpts = {targets: this.DOM.content};
anime(Object.assign(contentAnimOpts, config[dir].content));
}
if ( config[dir].trigger ) {
anime.remove(this.DOM.triggerSpan);
let triggerAnimOpts = {targets: this.DOM.triggerSpan};
anime(Object.assign(triggerAnimOpts, config[dir].trigger));
}
if ( config[dir].deco ) {
anime.remove(this.DOM.deco);
let decoAnimOpts = {targets: this.DOM.deco};
anime(Object.assign(decoAnimOpts, config[dir].deco));
}
}
destroy() {
this.DOM.trigger.removeEventListener('mouseenter', this.mouseenterFn);
this.DOM.trigger.removeEventListener('mouseleave', this.mouseleaveFn);
this.DOM.trigger.removeEventListener('touchstart', this.mouseenterFn);
this.DOM.trigger.removeEventListener('touchend', this.mouseleaveFn);
}
}
const init = (() => new Tooltip(tooltip))();
};
سون لرن • آموزش...
ما را در سایت سون لرن • آموزش دنبال می کنید
برچسب : انیمیشن, نویسنده : استخدام کار 7learn بازدید : 252 تاريخ : چهارشنبه 12 مهر 1396 ساعت: 6:17