Skip to content

Instantly share code, notes, and snippets.

@mathiasvr
Created October 15, 2016 18:37
Show Gist options
  • Save mathiasvr/2f7235f67e494f743ab722cc93a46fda to your computer and use it in GitHub Desktop.
Save mathiasvr/2f7235f67e494f743ab722cc93a46fda to your computer and use it in GitHub Desktop.
requirebin sketch
var onHold = require('on-hold')
var i = 0
var div = document.createElement('div')
var btn = document.createElement('button')
btn.textContent = 'Press and Hold'
document.body.appendChild(btn)
document.body.appendChild(div)
onHold(btn, function () {
div.textContent = i++
})
setTimeout(function(){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}({"on-hold":[function(require,module,exports){module.exports=function(element,opts,action){if(typeof opts==="function")action=opts;var wait=opts&&opts.wait||500;var interval=opts&&opts.interval||200;var tid=null;element.addEventListener("mousedown",hold);element.addEventListener("mouseup",release);element.addEventListener("mouseout",release);function hold(){action();tid=setTimeout(hold,tid?interval:wait)}function release(){clearTimeout(tid);tid=null}}},{}]},{},[]);var onHold=require("on-hold");var i=0;var div=document.createElement("div");var btn=document.createElement("button");btn.textContent="Press and Hold";document.body.appendChild(btn);document.body.appendChild(div);onHold(btn,function(){div.textContent=i++})},0);
{
"name": "on-hold-example",
"version": "1.0.0",
"dependencies": {
"on-hold": "1.0.2"
}
}
<!-- contents of this file will be placed inside the <body> -->
<!-- contents of this file will be placed inside the <head> -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment