Skip to content

Commit

Permalink
🎨 docs
Browse files Browse the repository at this point in the history
  • Loading branch information
gaoryrt committed Jun 19, 2018
1 parent 77cc37c commit 4341d94
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 23 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,23 @@ new Flip({
node: $('.flip'),
from: 9527,
to: 42,
duration: 2000
duration: 2
})
```

### more complex usage
```
new Flip({
node: $('.flip'),
from: 73,
to: 25,
duration: 2,
delay: 1,
easeFn: function(pos) {
if ((pos/=0.5) < 1) return 0.5*Math.pow(pos,3);
return 0.5 * (Math.pow((pos-2),3) + 2);
},
systemArr: ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖']
})
```

Expand Down
2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
<title>demo</title>
</head>
<body>
<div class="app"></div>
<div class="flip"></div>
</body>
</html>
17 changes: 6 additions & 11 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import './main.css'
import Flip from '../flip'

const el = new Flip({
node: document.querySelector('.app'),
from: 1000,
duration: .5
})
const $ = s => document.querySelector(s)

let num = 1001
setInterval(() => {
// const num = ~~(Math.random() * 9999)
num += 3
el.flipTo({to: num})
}, 1000)
new Flip({
node: $('.flip'),
from: 9527,
to: 42
})
10 changes: 0 additions & 10 deletions example/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,4 @@ html {
margin: 0;
padding: 0;
box-sizing: border-box;
}

.number-flip {
position: relative;
overflow: hidden;
}

.ctnr {
position: relative;
display: inline-block;
}
5 changes: 5 additions & 0 deletions flip.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,22 @@ module.exports = class flip {
this.to = to || 0
this.node = node
this._initHTML(maxLenNum(this.from, this.to))
if (!to) return
if (delay) setTimeout(() => {this.flipTo({to: this.to})}, delay * 1000)
else this.flipTo({to: this.to})
}

_initHTML(digits) {
this.node.classList.add('number-flip')
this.node.style.position = 'relative'
this.node.style.overflow = 'hidden'
;[...Array(digits).keys()].forEach(i => {
const ctnr = g(`ctnr ctnr${i}`)(
...this.systemArr.map(i => g('digit')(i)),
g('digit')(this.systemArr[0])
)
ctnr.style.position = 'relative'
ctnr.style.display = 'inline-block'
this.ctnrArr.unshift(ctnr)
this.node.appendChild(ctnr)
this.beforeArr.push(0)
Expand Down

0 comments on commit 4341d94

Please sign in to comment.