JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
HTML Settings
Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
div#head.box
div.box
div.box
div.box
div.box
div.box
div.box
colors = red orange yellow green cyan blue purple
reverse(i)
100 - i
.box
position absolute
transform translate(10px, 10px)
transition 0.1s transform ease-out
width 40px
height 40px
background orange
cursor pointer
for color, i in colors
&:nth-child({i + 1})
background color
z-index reverse(i)
if color != red
pointer-events: none
const headBox = document.getElementById('head')
const boxes = document.getElementsByClassName('box')
const mouseDown$ = Rx.Observable.fromEvent(headBox, 'mousedown')
const mouseMove$ = Rx.Observable.fromEvent(document, 'mousemove')
const mouseUp$ = Rx.Observable.fromEvent(document, 'mouseup')
const delayBoxes$ = Rx.Observable.from([].slice.call(boxes, 0))
.zip(Rx.Observable.interval(100).startWith(0), (box) => box)
mouseDown$.map((e) => {
const pos = getTranslate(headBox)
return {
pos,
event: e,
}
})
.switchMap((initialState) => {
const initialPos = initialState.pos
const { clientX, clientY } = initialState.event
return mouseMove$.map((moveEvent) => ({
x: moveEvent.clientX - clientX + initialPos.x,
y: moveEvent.clientY - clientY + initialPos.y,
}))
.takeUntil(mouseUp$)
})
.mergeMap((pos) => {
return delayBoxes$.do((box) => {
setTranslate(box, pos)
})
})
.subscribe()
function getTranslate (element) {
const style = getComputedStyle(element)
const regExp = /matrix\((\d+,\s){4}(\d+),\s(\d+)/i
const result = style.transform.match(regExp)
if (result) {
return {
x: parseInt(result[2], 10),
y: parseInt(result[3], 10)
}
} else {
return {
x: 0,
y: 0
}
}
}
function setTranslate (element, pos) {
element.style.transform = `translate(${pos.x}px, ${pos.y}px)`
}
Also see: Tab Triggers