{"id":15379326,"url":"https://github.com/yaireo/position","last_synced_at":"2025-06-11T20:06:49.252Z","repository":{"id":42623300,"uuid":"403244804","full_name":"yairEO/position","owner":"yairEO","description":"Position a DOM element at a certain X,Y or next to another element","archived":false,"fork":false,"pushed_at":"2024-08-24T08:27:21.000Z","size":302,"stargazers_count":7,"open_issues_count":5,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T05:56:06.208Z","etag":null,"topics":["dom","elements","placement","position","positioning"],"latest_commit_sha":null,"homepage":"https://jsbin.com/beqosub/edit?html,css,output","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/yairEO.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-05T07:35:40.000Z","updated_at":"2024-09-14T10:27:26.000Z","dependencies_parsed_at":"2024-08-07T12:55:59.420Z","dependency_job_id":"aa99e040-a94f-40e0-aee6-6bb75c6cd235","html_url":"https://github.com/yairEO/position","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yairEO%2Fposition","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yairEO%2Fposition/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yairEO%2Fposition/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yairEO%2Fposition/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yairEO","download_url":"https://codeload.github.com/yairEO/position/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249119556,"owners_count":21215765,"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":["dom","elements","placement","position","positioning"],"created_at":"2024-10-01T14:18:49.180Z","updated_at":"2025-04-15T17:36:23.611Z","avatar_url":"https://github.com/yairEO.png","language":"JavaScript","readme":"\u003cp align=\"center\"\u003e\n  \u003ca href='https://jsbin.com/beqosub/edit?html,css,output' title='See demo'\u003e\u003cimg src=\"demo.png\"\u003e\u003ca/\u003e\n  \u003cbr\u003e\u003cbr\u003e\n  \u003ca href='https://www.npmjs.com/package/@yaireo/position'\u003e\n      \u003cimg src=\"https://badgen.net/npm/v/@yaireo/position?color=red\" /\u003e\n  \u003c/a\u003e\n  \u003cimg src=\"https://badgen.net/bundlephobia/minzip/@yaireo/position?color=green\" /\u003e\n  \u003cimg src=\"https://badgen.net/npm/dw/@yaireo/position?color=blue\" /\u003e\n\u003c/p\u003e\n\n\u003ch1 align=\"center\"\u003e\n  Position DOM element at X,Y or next to another element\n\u003c/h1\u003e\n\n## Install\n\n```bash\nnpm i @yaireo/position -S\n```\n\n### UMD file link:\n\n    https://unpkg.com/@yaireo/position\n\n## Example\n```js\nimport position from '@yaireo/position'\n\nposition({\n  // the element wished to be positioned in a certain place\n  target: targetElement,\n\n  // reference DOM element or an Object like so: {x:10, y:20}\n  ref: refElement,\n\n  // [optional] default target plaement string, relative to the ref\n  // first string value is horizontal and then vertical placement. Examples:\n  // 'left center', 'right below', 'center center'\n  placement:'center above',\n\n  // [optional] distance from reference element\n  offset: [20],\n\n  // [optional] by default the positioning updates within a RequestAnimationFrame callback,\n  //but this can cause painting delays when resizing or scrolling fast.\n  useRaf: false,\n})\n```\n\nThis scripts places an element next to another element (at a certain prefered relative place).\nIf you want to update the targer's position (relative to its referece node) when the page scrolls or resizes\nI advice adding observers:\n\n```js\nconst observerCallback = () =\u003e position({ target:targetElement, ref:refElement })\n\n// create observers instances\nconst resizeObserver = new ResizeObserver(observerCallback)\nconst intersectionObserver = new IntersectionObserver(observerCallback, {root:document, threshold:1})\n\n// start observing (using the instances created above)\nresizeObserver.observe(document.body)\nintersectionObserver.observe(targetElement)\n```\n\n## CSS\n\nThis script adds *CSS variables* (custom properties) on the *target* element:\n\n| CSS Variable        |\n| ------------------- |\n| `pos-left`          |\n| `pos-top`           |\n| `pos-target-width`  |\n| `pos-target-height` |\n| `pos-ref-width`     |\n| `pos-ref-height`    |\n| `pos-ref-left`      |\n| `pos-ref-top`       |\n| `window-scroll-y`   |\n| `window-scroll-x'`  |\n\nUsing the above mix of variables, write this CSS in your code to position the target:\n\n```css\n[positioned]{\n  --x: calc(var(--pos-left) + var(--window-scroll-x));\n  --y: calc(var(--pos-top) + var(--window-scroll-y));\n  position: absolute;\n  z-index: 999999;\n  top: 0;\n  left: 0;\n  transform: translate(calc(var(--x) * 1px),\n                       calc(var(--y) * 1px));\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyaireo%2Fposition","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyaireo%2Fposition","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyaireo%2Fposition/lists"}