Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Forcify is a JavaScript library help you polyfill 3D/Force Touch in any device.
Use Force Touch in any device, today.
Forcify is a JavaScript library help you polyfill 3D/Force Touch in any device. All you need is just deal with the e.force
value, dead simple:
var ele = document.querySelector('#force')
new Forcify(ele).on('force', (e) => {
doSomething(e.force)
})
Waaaaait! Can 3D/Force Touch, a hardware feature, be really polyfilled? No, but we can emulate it with Long Press!
Forcify can help you start supporting Force Touch feature to your app or site without hesitate.
Check out demo in any unsupported device →
Download Forcify.min.js (2.4kb not gzipped)
!== 0
force value), Forcify would help you shim these weird browser, you would not get a wrong force value to mis-trigger your handlers.force
value after long press triggered, which help your shortcut actions designed for Force Touch can be used in any other device.Also, Forcify provide many options such as FALLBACK_TO_LONGPRESS
, LONG_PRESS_DELAY
, LONG_PRESS_DURATION
and SHIM_WEIRD_BROWSER
to let you customize it as you need, more on Document.
3D/Force Touch release new webkitForce
(Force Touch) and force
(3D Touch) property to mouse and touch events. But, different browsers implement them in really different and weird way, let's have a quick glance:
Desktop:
Browser | support | force | webkitForce | events |
---|---|---|---|---|
OSX Safari | Force Touch | null | 0 ~ 1 by Force | webkitmouseforce |
OSX Safari | null | null | 1 | mouse |
Chrome | null | null | null | mouse |
Chrome Touchable-PC | null | 0 | null | touch |
Mobile:
Browser | support | force | webkitForce | events |
---|---|---|---|---|
iPhone Safari | 3D Touch | 0 ~ 1 by Force | null | touch |
iPhone Safari | null | 0 | null | touch |
Chrome Mobile | null | 1 | 1 | touch |
Chrome Mobile Nexus5 | null | 0 ~ 1 by touch area! | same | touch |
Chrome Emulator | null | 1 | null | touch |
Android Browser | null | null | null | touch |
As you see, even just supporting the real OSX Force Touch and iOS 3D Touch you need write twice, and it is not that easy as you thought:
webkitmouseforcewillbegin
and webkitmouseforcechange
to get value every time changed directly.touchdown
, touchmove
, touchup
only. We has to use polling to repeat poll the force
value during the entire touch duration.Things gonna worse when you look at Chrome. Chrome on all device nowadays haven't any Force Touch support, but It provide a tricky !== 0
force value in many platform!
force=1
and webkitForce=1
, which means your "Force Actions" would be ALWAYS triggered just by a clickThat is why Forcify comes to help.
Check out
example/
to get a detailed example
The simplest way to use Forcify is adding it to your HTML page with <script>
:
<script src="/path/to/forcify.min.js"></script>
And you can also include Forcify in your JavaScript bundle with ES6, CommonJS or AMD syntax.
$ npm install forcify --save
Create a new Forcify instance, and use on
to listen force
event:
var ele = document.querySelector('#force')
var $ele = new Forcify(ele)
// add event listener
$ele.on('force', (e) => {
doSomething(e.force)
})
You can pass options
into the Forcify
constructor to override default options:
// only emit event in real supported device.
var $noFallback = new Forcify(ele, {
FALLBACK_TO_LONGPRESS: false
})
// I am sure there would be a mess watting for u
var $noShim = new Forcify(ele, {
SHIM_WEIRD_BROWSWR: false
})
// not easy to trigger...
var $longLongPress = new Forcify(ele, {
LONG_PRESS_DELAY: 10000 //ms
})
Also, you can use Forcify.config
to override default options globally
// let's make duration of the force grow slower.
Forcify.config({
LONG_PRESS_DURATION: 500
})
Default options for Forcify instance.
LONG_PRESS_DELAY: 200
Number
200(ms)
LONG_PRESS_DURATION: 100
Number
1000(ms)
FALLBACK_TO_LONGPRESS: true
Boolean
true
SHIM_WEIRD_BROWSER: true
Boolean
true
Object save the results of dynamic detection. All fields is Boolean
type and default false
.
TOUCH3D
Unfortunately there is not a feature detection for 3DTouch so far, so Forcify use a dynamic detection to detect it.
If Forcify detects that force is support, all hacking stop.
OSXFORCE
OSX support real webkit force touch
WEIRD_CHROME
Chrome Mobile give any touchevent a 'force' property with value: 1.
Forcify has to hack it.
Forcify not detect Weird Chrome by UA but behaviors.
Special thank to:
FAQs
Forcify is a JavaScript library help you polyfill 3D/Force Touch in any device.
The npm package forcify receives a total of 0 weekly downloads. As such, forcify popularity was classified as not popular.
We found that forcify demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.