Skip to content

Commit

Permalink
refactor(range): remove animejs
Browse files Browse the repository at this point in the history
  • Loading branch information
wuda-io committed Dec 18, 2023
1 parent 859471d commit 4a18fbc
Showing 1 changed file with 31 additions and 24 deletions.
55 changes: 31 additions & 24 deletions src/range.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import anim from "animejs";

import { Component, BaseOptions, InitElements, MElement } from "./component";

export interface RangeOptions extends BaseOptions {};
Expand Down Expand Up @@ -136,18 +134,24 @@ export class Range extends Component<RangeOptions> {
_handleRangeBlurMouseoutTouchleave = () => {
if (!this._mousedown) {
const paddingLeft = parseInt(getComputedStyle(this.el).paddingLeft);
const marginLeft = 7 + paddingLeft + 'px';
const marginLeftText = 7 + paddingLeft + 'px';
if (this.thumb.classList.contains('active')) {
anim.remove(this.thumb);
anim({
targets: this.thumb,
height: 0,
width: 0,
top: 10,
easing: 'easeOutQuad',
marginLeft: marginLeft,
duration: 100
});
const duration = 100;
// from
this.thumb.style.transition = 'none';
setTimeout(() => {
this.thumb.style.transition = `
height ${duration}ms ease,
width ${duration}ms ease,
top ${duration}ms ease,
margin ${duration}ms ease
`;
// to
this.thumb.style.height = '0';
this.thumb.style.width = '0';
this.thumb.style.top = '0';
this.thumb.style.marginLeft = marginLeftText;
}, 1);
}
this.thumb.classList.remove('active');
}
Expand All @@ -168,17 +172,20 @@ export class Range extends Component<RangeOptions> {

_showRangeBubble() {
const paddingLeft = parseInt(getComputedStyle(this.thumb.parentElement).paddingLeft);
const marginLeft = -7 + paddingLeft + 'px'; // TODO: fix magic number?
anim.remove(this.thumb);
anim({
targets: this.thumb,
height: 30,
width: 30,
top: -30,
marginLeft: marginLeft,
duration: 300,
easing: 'easeOutQuint'
});
const marginLeftText = -7 + paddingLeft + 'px'; // TODO: fix magic number?
const duration = 300;
// easeOutQuint
this.thumb.style.transition = `
height ${duration}ms ease,
width ${duration}ms ease,
top ${duration}ms ease,
margin ${duration}ms ease
`;
// to
this.thumb.style.height = '30px';
this.thumb.style.width = '30px';
this.thumb.style.top = '-30px';
this.thumb.style.marginLeft = marginLeftText;
}

_calcRangeOffset(): number {
Expand Down

0 comments on commit 4a18fbc

Please sign in to comment.