Skip to content

Commit

Permalink
Make the border-width dance (Resolve #64)
Browse files Browse the repository at this point in the history
  • Loading branch information
maryzam authored and Okazari committed Feb 15, 2018
1 parent dc2c9ef commit 29e8865
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 5 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<♫/> Rythm.js - v2.2.2
<♫/> Rythm.js - v2.2.3
========

[![Build Status](https://travis-ci.org/Okazari/Rythm.js.svg?branch=master)](https://travis-ci.org/Okazari/Rythm.js)
Expand Down Expand Up @@ -190,6 +190,9 @@ Here are the build in dances and their options
+ Neon
+ from : Array of integer between 0 and 255 corresponding to a RGB color. Default: `[0,0,0]`
+ to : Array of integer between 0 and 255 corresponding to a RGB color. Default: `[255,255,255]`
+ borderWidth
+ min : Minimum value given to `border-width`. Default: `0`
+ max : Maximum value given to `borderr-width`. Default: `5`

To see each visual effect, you can go to the [Demo](https://okazari.github.io/Rythm.js/)

Expand Down
2 changes: 2 additions & 0 deletions demo/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ window.onload = function() {
from: [255, 255, 0],
to: [255, 0, 0],
})
rythm.addRythm('borderWidth1', 'borderWidth', 0, 2)
rythm.addRythm('borderWidth2', 'borderWidth', 0, 2, { min: 2, max: 10 })
rythm.addRythm('radius1', 'radius', 0, 10, { min: 0, max: 30 })
rythm.addRythm('radius2', 'radius', 0, 10, { reverse: true, min: 0, max: 30 })
rythm.addRythm('blur1', 'blur', 0, 10)
Expand Down
10 changes: 9 additions & 1 deletion demo/rythm.css
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,19 @@ section:last-child {
.radius2,
.borderColor1,
.borderColor2,
.borderColor3 {
.borderColor3,
.borderWidth1,
.borderWidth2 {
border: 2px solid white;
padding: 1px;
}

.borderWidth1,
.borderWidth2 {
min-width: 15px;
min-height: 15px;
}

/* Pretty printing styles. Used with prettify.js. */
/* Vim sunburst theme by David Leibovic */

Expand Down
29 changes: 28 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<!-- <audio id="audio" src="samples/rythmC" autoplay=""></audio> -->
<div class="container">
<h1 class="shake3">
Rythm.js - v2.2.2
Rythm.js - v2.2.3
</h1>
<h2>
A javascript library that makes your page dance.
Expand Down Expand Up @@ -52,6 +52,33 @@ <h3>
use css class 'rythm-high'
</pre>
</div>
</section>
<h1>
Added in v2.2.3
</h1>
<section>
<h3>
Border-Width
</h3>
<div class="demo">
<div class="rythm">
<div class="borderWidth1"></div>
</div>
<pre class="prettyprint">
rythm.addRythm('borderWidth1', 'borderWidth', 0, 2)
</pre>
</div>
<div class="demo">
<div class="rythm">
<div class="borderWidth2"></div>
</div>
<pre class="prettyprint">
rythm.addRythm('borderWidth2', 'borderWidth', 0, 2, {
min: 2,
max: 10
})
</pre>
</div>
</section>
<h1>
Added in v2.2.2
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion rythm.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,20 @@
elem.style.letterSpacing = ''
}

var borderWidth = function(elem, value) {
var options =
arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}

var max = !isNaN(options.max) ? options.max : 5
var min = !isNaN(options.min) ? options.min : 0
var borderWidth = (max - min) * value + min
elem.style.borderWidth = borderWidth + 'px'
}

var reset$12 = function reset(elem) {
elem.style.borderWidth = ''
}

var Dancer = (function() {
function Dancer() {
classCallCheck(this, Dancer)
Expand All @@ -459,6 +473,7 @@
this.registerDance('swing', swing, reset$9)
this.registerDance('neon', neon, reset$10)
this.registerDance('kern', kern, reset$11)
this.registerDance('borderWidth', borderWidth, reset$12)
}

createClass(Dancer, [
Expand Down Expand Up @@ -609,4 +624,3 @@

return Rythm$1
})
//# sourceMappingURL=rythm.js.map
4 changes: 4 additions & 0 deletions src/Dancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import blur, { reset as blurReset } from './dances/blur.js'
import swing, { reset as swingReset } from './dances/swing.js'
import neon, { reset as neonReset } from './dances/neon.js'
import kern, { reset as kernReset } from './dances/kern.js'
import borderWidth, {
reset as borderWidthReset,
} from './dances/border-width.js'

class Dancer {
constructor() {
Expand All @@ -30,6 +33,7 @@ class Dancer {
this.registerDance('swing', swing, swingReset)
this.registerDance('neon', neon, neonReset)
this.registerDance('kern', kern, kernReset)
this.registerDance('borderWidth', borderWidth, borderWidthReset)
}

registerDance(type, dance, reset = () => {}) {
Expand Down
10 changes: 10 additions & 0 deletions src/dances/border-width.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default (elem, value, options = {}) => {
const max = !isNaN(options.max) ? options.max : 5
const min = !isNaN(options.min) ? options.min : 0
const borderWidth = (max - min) * value + min
elem.style.borderWidth = `${borderWidth}px`
}

export const reset = elem => {
elem.style.borderWidth = ''
}

0 comments on commit 29e8865

Please sign in to comment.