{"id":22486219,"url":"https://github.com/dinohamzic/displaceable","last_synced_at":"2025-04-09T20:02:19.322Z","repository":{"id":33581454,"uuid":"159705933","full_name":"dinohamzic/displaceable","owner":"dinohamzic","description":"A tiny, performant and configurable JavaScript library that smoothly displaces elements on mouse move.","archived":false,"fork":false,"pushed_at":"2023-01-03T15:27:24.000Z","size":10359,"stargazers_count":222,"open_issues_count":10,"forks_count":12,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-09T20:01:34.621Z","etag":null,"topics":["animation","css-transforms","css-transitions","es6","javascript","no-dependencies"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dinohamzic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-29T17:51:26.000Z","updated_at":"2024-10-07T22:34:29.000Z","dependencies_parsed_at":"2023-01-15T01:45:19.653Z","dependency_job_id":null,"html_url":"https://github.com/dinohamzic/displaceable","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dinohamzic%2Fdisplaceable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dinohamzic%2Fdisplaceable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dinohamzic%2Fdisplaceable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dinohamzic%2Fdisplaceable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dinohamzic","download_url":"https://codeload.github.com/dinohamzic/displaceable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103864,"owners_count":21048245,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["animation","css-transforms","css-transitions","es6","javascript","no-dependencies"],"created_at":"2024-12-06T17:14:07.764Z","updated_at":"2025-04-09T20:02:19.275Z","avatar_url":"https://github.com/dinohamzic.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# displaceable\n\nA tiny JavaScript library that handles super smooth element displacement on mouse move. Inspired by this [shot](https://dribbble.com/shots/5594494-Molley-Heltz-Inspiration-Page-Animation).\n\n![Displaceable screen capture](screen-capture.gif)\n\n---\n\n## Demo and code examples\n\nLive [demo](https://subtlebits.com/projects/displaceable) and React implementation [example](https://github.com/dinohamzic/www-subtlebits-com/blob/master/pages/projects/displaceable.js).\n\n## Setup\n\n#### Install:\n\n```bash\nnpm install displaceable\n```\n\n## Basic usage\n\n#### Import:\n\n```js\nimport Displaceable from 'displaceable';\n```\n\n#### Initialize:\n\n```js\n// single Node\nconst displaceable = new Displaceable(document.getElementById('id'));\n```\n\nor\n\n```js\n// NodeList\nconst displaceable = new Displaceable(document.querySelectorAll('img'));\n```\n\nor\n\n```js\n// array of Nodes\nconst displaceable = new Displaceable([\n  document.getElementById('id-1'),\n  document.getElementById('id-2'),\n  document.getElementById('id-3')\n]);\n```\n\n## Configuration\n\n#### `settings` object\n\nYou can pass an object as the second parameter of `Displaceable()` to modify the instance settings.\n\n```js\nconst displaceable = new Displaceable(document.getElementById('node-id'), {\n  displaceFactor: 5,\n  lockY: true,\n  resetTime: 500,\n  skewFactor: 10,\n  trigger: document.getElementById('trigger-id')\n});\n```\n\nProperty | Type | Default | Description\n------ | ---- | ------- | -----------\ndisplaceFactor | 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.\nlockX | boolean | false | If set to `true`, Nodes will only move on the Y axis.\nlockY | boolean | false | If set to `true`, Nodes will only move on the X axis.\nresetTime | number | 1000 | How fast the Nodes will return to their original position (in milliseconds).\nskewFactor | 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.\ntrigger | window\\|Node | window | The Node that triggers the displacement. It can be any Node with height and width greater than zero.\n\n#### Data attributes:\n\n- `data-displace-factor`\n- `data-lock-x`\n- `data-lock-y`\n- `data-skew-factor`\n\nTo 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.\n\n```html\n\u003cimg\n  data-displace-factor=\"10\"\n  data-skew-factor=\"10\"\n  id=\"img-id\"\n/\u003e\n\n\u003cdiv\n  data-lock-y=\"true\"\n  id=\"div-id\"\n\u003e\n  I'm displaceable and I can only move horizontally!\n\u003c/div\u003e\n```\n\n## Methods\n\n#### `destroy`: destroys all the associated events of a particular instance\n\n```\nconst displaceable = new Displaceable(document.getElementById('id'));\n\ndisplaceable.destroy();\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdinohamzic%2Fdisplaceable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdinohamzic%2Fdisplaceable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdinohamzic%2Fdisplaceable/lists"}