JavaScript Library For 3D Touch and Pointer On Web | Pressure.js

Pressure is a JavaScript library for handling both Force Touch and 3D Touch on the web, bundled into a single library with a simple API that makes working with them painless.

pointer events javascript, pointer js, detect touch events javascript, pressure sensitivity test online, javascript touch events, pressure js

3D Carousel With Mouse And Touch Interactions

How to make use of it:

To get began, include the pressure.js JavaScript file within the doc.

<script src="pressure.js"></script>

Get again a change value on all components matching the selector.

Pressure.change('#el1', function(force, event){
  console.log(force);
  // "this" is the element(s) returned by the closure
  this.style.width = (200 * force + 200) + 'px';
  this.innerHTML = force;
});

Get again a change value on ONLY components that assist Force Touch (New Mac’s).

Pressure.changeForceTouch('#el2', function(force, event){
  this.style.width = Math.max((200 * force), 200) + 'px';
  this.innerHTML = force;
});

Get again a change worth on ONLY components that assist 3D Touch.

Pressure.change('#el3', function(force, event){
  this.style.width = (200 * force + 200) + 'px';
  this.innerHTML = force;
});

This structure can be utilized in any strategy of Pressure. The failure block will return with an “error” and message displaying why the device doesn’t assist 3D Touch.

var block = {
  start: function(){
  },

  change: function(force, event){
    this.style.width = ((200 * force) + 200) + 'px';
    this.innerHTML = force;
    this.style.backgroundColor = "rgb(" + parseInt(map(force, 0, 1, 255, 0)) + ",0," + parseInt(map(force, 0, 1, 0, 255)) +")";
    this.style.color = force > 0.4 ? 'white' : 'black';
  },

  startDeepPress: function(event){
    // this is called on "force click" / "deep press", aka once the force is greater than 0.5
  },
  endDeepPress: function(){
    // this is called when the "force click" / "deep press" end
  },

  end: function(){
    this.style.width = '200px';
    this.innerHTML = 0;
    this.style.backgroundColor = 'red';
    this.style.color = 'black';
  },

  unsupported: function(){
    console.log(this);
    this.innerHTML = 'Your device / browser does not support this :(';
  }
}

Pressure.set('#el1', block);
Pressure.setForceTouch('#el2', block);
Pressure.set3DTouch('#el3', block);

function map(x, in_min, in_max, out_min, out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

JavaScript Library For 3D Touch Handling, Pressure js Plugin/Github


See Demo And Download

Official Website(stuyam): Click Here

This superior jQuery/javascript plugin is developed by stuyam. For extra Advanced Usages, please go to the official website.

Related Posts

Iconpicker-Bootstrap-5

[Icon Picker] Iconpicker for Bootstrap 5 Icons Library

Bootstrap 5-based icon picker which supports any icon libraries like Bootstrap Icons, Font Awesome[fontawesome.com], etc. Must Read: 1000+ Pixel Perfect SVG Icons For Vue Components | Unicons How…

bootstrap-multiple-image-upload-with-preview

Bootstrap Multiple Image Upload with Preview and Delete | ImagesLoader

ImagesLoader is a standard bootstrap image upload plugin that provides an easy-to-use and nice-looking interface for uploading multiple images to a web server. Must Read: HTML 5…

Animating-Split-Flap-Displays-fallblatt

A Lightweight jQuery Plugin for Animating Split-Flap Displays | fallblatt

fallblatt is a lightweight jQuery plugin for animating split screens. This jQuery plugin allows you to include such offers in your web application. Everything from virtual departure…

bootstrap-5-dark-theme

Dark & Light Switch Mode Toggle for Bootstrap 5

Switching to dark mode is done by toggling HTML tags that include -dark or -light as a category. It is made by manipulating the DOM with JavaScript. The text color also changes depending…

jQuery-SyoTimer-Plugin

jQuery Plugin for Countdown Timer on HTML Page | SyoTimer

yoTimer jQuery plugin allows you to create digital style countdowns/periodic timers on the webpage, with callbacks support and timezone/translation customization. Features Periodic count with the specified period…

vue-js-periodic-table

Dynamic, Data-driven Periodic Table built with Vue.js

Periodicity is a dynamic, data-driven periodic table created with Vue.js that uses D3 animations and graphs to show the beauty of periodic trends. Built With vue.js (component…