Skip to content

Instantly share code, notes, and snippets.

@olivierrr
Created January 29, 2015 23:43
Show Gist options
  • Save olivierrr/b7433c999898961bacdb to your computer and use it in GitHub Desktop.
Save olivierrr/b7433c999898961bacdb to your computer and use it in GitHub Desktop.
requirebin sketch
var knob = require('dom-knob')
var elem = document.body.appendChild(document.createElement('div'))
elem.style.background = 'red'
elem.style.padding = '100px'
elem.style.fontSize = '30px'
knob(elem, function(deg) {
elem.innerHTML = deg
})
require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({"dom-knob":[function(require,module,exports){module.exports=knob;function knob(elem,cb){if(typeof elem!=="object"){throw new Error("knob(elem, callback")}if(typeof cb!=="function"){throw new Error("knob(elem, callback")}var isDragging=false;document.addEventListener("mouseup",onUp);document.addEventListener("touchend",onUp);elem.addEventListener("mousedown",onDown);elem.addEventListener("touchstart",onDown);document.addEventListener("mousemove",onMove);document.addEventListener("touchmove",onMove);function onDown(){isDragging=true}function onUp(){isDragging=false}function onMove(e){if(!isDragging){return}if(e.touches){e=e.touches[0]}var rect=elem.getBoundingClientRect();var centerX=rect.width/2+rect.left;var centerY=rect.height/2+rect.top;var radians=Math.atan2(e.clientX-centerX,e.clientY-centerY);cb(Math.abs(radians*(180/Math.PI)-180))}}},{}]},{},[]);var knob=require("dom-knob");var elem=document.body.appendChild(document.createElement("div"));elem.style.background="red";elem.style.padding="100px";elem.style.fontSize="30px";knob(elem,function(deg){elem.innerHTML=deg});
{
"name": "requirebin-sketch",
"version": "1.0.0",
"dependencies": {
"dom-knob": "1.0.0"
}
}
<style type='text/css'>html, body { margin: 0; padding: 0; border: 0; }
body, html { height: 100%; width: 100%; }</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment