dinohamzic / Displaceable
Licence: mit
A tiny, performant and configurable JavaScript library that smoothly displaces elements on mouse move.
Stars: ✭ 219
Programming Languages
javascript
184084 projects - #8 most used programming language
es6
455 projects
Labels
Projects that are alternatives of or similar to Displaceable
Minidyndns
A simple DynDNS server with an build in HTTP interface to update IPs
Stars: ✭ 101 (-53.88%)
Mutual labels: no-dependencies
Climake
The simplistic, dependency-free cli library ✨
Stars: ✭ 139 (-36.53%)
Mutual labels: no-dependencies
Zingtouch
A JavaScript touch gesture detection library for the modern web
Stars: ✭ 2,019 (+821.92%)
Mutual labels: no-dependencies
Cli11
CLI11 is a command line parser for C++11 and beyond that provides a rich feature set with a simple and intuitive interface.
Stars: ✭ 1,880 (+758.45%)
Mutual labels: no-dependencies
Houdini
A simple, accessible show-and-hide/accordion script.
Stars: ✭ 148 (-32.42%)
Mutual labels: no-dependencies
Right Height
Dynamically set content areas of different lengths to the same height.
Stars: ✭ 91 (-58.45%)
Mutual labels: no-dependencies
Variant Lite
variant lite - A C++17-like variant, a type-safe union for C++98, C++11 and later in a single-file header-only library
Stars: ✭ 187 (-14.61%)
Mutual labels: no-dependencies
Eneida
Experimental demoscene project using C99 and Direct3D 12. Fully standalone with custom windows, and d3d12 headers. No Windows SDK, libc or Visual Studio dependency. C and HLSL compilers included.
Stars: ✭ 125 (-42.92%)
Mutual labels: no-dependencies
Coingecko Api
A Node.js wrapper for the CoinGecko API with no dependencies.
Stars: ✭ 159 (-27.4%)
Mutual labels: no-dependencies
Tortellini
A really stupid INI file format for C++11
Stars: ✭ 118 (-46.12%)
Mutual labels: no-dependencies
Expected Lite
expected lite - Expected objects in C++11 and later in a single-file header-only library
Stars: ✭ 158 (-27.85%)
Mutual labels: no-dependencies
Scope guard
A modern C++ scope guard that is easy to use but hard to misuse.
Stars: ✭ 108 (-50.68%)
Mutual labels: no-dependencies
Catch2
A modern, C++-native, test framework for unit-tests, TDD and BDD - using C++14, C++17 and later (C++11 support is in v2.x branch, and C++03 on the Catch1.x branch)
Stars: ✭ 14,330 (+6443.38%)
Mutual labels: no-dependencies
Magic enum
Static reflection for enums (to string, from string, iteration) for modern C++, work with any enum type without any macro or boilerplate code
Stars: ✭ 2,340 (+968.49%)
Mutual labels: no-dependencies
Long Press Event
Adds `long-press` event to the DOM in 1k of pure JavaScript
Stars: ✭ 187 (-14.61%)
Mutual labels: no-dependencies
Mailtoui
A simple way to enhance your mailto links with a convenient user interface.
Stars: ✭ 162 (-26.03%)
Mutual labels: no-dependencies
displaceable
A tiny JavaScript library that handles super smooth element displacement on mouse move. Inspired by this shot.
Demo and code examples
Live demo and React implementation example.
Setup
Install:
npm install displaceable
Basic usage
Import:
import Displaceable from 'displaceable';
Initialize:
// single Node
const displaceable = new Displaceable(document.getElementById('id'));
or
// NodeList
const displaceable = new Displaceable(document.querySelectorAll('img'));
or
// array of Nodes
const displaceable = new Displaceable([
document.getElementById('id-1'),
document.getElementById('id-2'),
document.getElementById('id-3')
]);
Configuration
settings
object
You can pass an object as the second parameter of Displaceable()
to modify the instance settings.
const displaceable = new Displaceable(document.getElementById('node-id'), {
displaceFactor: 5,
lockY: true,
resetTime: 500,
skewFactor: 10,
trigger: document.getElementById('trigger-id')
});
Property | Type | Default | Description |
---|---|---|---|
displaceFactor | number | 3 | Multiplier for the translate transformation. The bigger the number, the more the Nodes will move. You can use a negative value to invert the direction of the movement. |
lockX | boolean | false | If set to true , Nodes will only move on the Y axis. |
lockY | boolean | false | If set to true , Nodes will only move on the X axis. |
resetTime | number | 1000 | How fast the Nodes will return to their original position (in milliseconds). |
skewFactor | number | 5 | Multiplier for the skew transformation. The bigger the number, the more Nodes will skew. You can use a negative value to invert the skewing direction. |
trigger | window|Node | window | The Node that triggers the displacement. It can be any Node with height and width greater than zero. |
Data attributes:
data-displace-factor
data-lock-x
data-lock-y
data-skew-factor
To control each Node independently, use the following data attributes. The value set in the data attribute will override the one in the settings
object only for that particular element.
<img
data-displace-factor="10"
data-skew-factor="10"
id="img-id"
/>
<div
data-lock-y="true"
id="div-id"
>
I'm displaceable and I can only move horizontally!
</div>
Methods
destroy
: destroys all the associated events of a particular instance
const displaceable = new Displaceable(document.getElementById('id'));
displaceable.destroy();
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].