made with esnextbin
Last active
October 6, 2016 06:09
-
-
Save trxcllnt/e8285775b235731c5d6d293204deec1c to your computer and use it in GitHub Desktop.
esnextbin sketch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>ESNextbin Sketch</title> | |
<!-- put additional styles and scripts here --> | |
</head> | |
<body> | |
<!-- put markup and other contents here --> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Gestures } from 'rxjs-gestures'; | |
const box = document.body.appendChild(document.createElement('div')); | |
box.style.width = `100px`; | |
box.style.height = `100px`; | |
box.style.position = `absolute`; | |
box.style.border = `1px solid black`; | |
box.style.background = `rgba(0,0,0,0.3)`; | |
const starts = Gestures.start(box).map((point) => { | |
console.log('start', point); | |
return point.event; | |
}).share(); | |
const pans = Gestures | |
.pan(starts) | |
.switchMap((pan) => pan | |
.decelerate(0.25, 15) | |
.takeUntil(starts.skip(1)) | |
.repeat() | |
); | |
pans.subscribe(({ pageXOriginX, originY, movementTotalX, movementTotalY }) => { | |
box.style.transform = `translate3d(${ | |
originX + movementTotalX}px, ${ | |
originY + movementTotalY}px, 0)`; | |
}); | |
console.log('ready'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "esnextbin-sketch", | |
"version": "0.0.0", | |
"dependencies": { | |
"rxjs-gestures": "1.0.5" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var _rxjsGestures = require('rxjs-gestures'); | |
var box = document.body.appendChild(document.createElement('div')); | |
box.style.width = '100px'; | |
box.style.height = '100px'; | |
box.style.position = 'absolute'; | |
box.style.border = '1px solid black'; | |
box.style.background = 'rgba(0,0,0,0.3)'; | |
var starts = _rxjsGestures.Gestures.start(box).map(function (point) { | |
console.log('start', point); | |
return point.event; | |
}).share(); | |
var pans = _rxjsGestures.Gestures.pan(starts).switchMap(function (pan) { | |
return pan.decelerate(0.25, 15).takeUntil(starts.skip(1)).repeat(); | |
}); | |
pans.subscribe(function (_ref) { | |
var pageXOriginX = _ref.pageXOriginX; | |
var originY = _ref.originY; | |
var movementTotalX = _ref.movementTotalX; | |
var movementTotalY = _ref.movementTotalY; | |
box.style.transform = 'translate3d(' + (originX + movementTotalX) + 'px, ' + (originY + movementTotalY) + 'px, 0)'; | |
}); | |
console.log('ready'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment