{"id":14988463,"url":"https://github.com/john-doherty/swiped-events","last_synced_at":"2025-05-15T10:06:42.917Z","repository":{"id":39615170,"uuid":"117478262","full_name":"john-doherty/swiped-events","owner":"john-doherty","description":"Adds `swiped` events to the DOM in 1k of pure JavaScript","archived":false,"fork":false,"pushed_at":"2024-04-27T19:12:55.000Z","size":820,"stargazers_count":592,"open_issues_count":8,"forks_count":173,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-05-09T03:03:46.896Z","etag":null,"topics":["cordova","html5","hybrid-apps","javascript","no-dependencies","swipe","touch","vanilla-js"],"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/john-doherty.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":"2018-01-15T00:19:38.000Z","updated_at":"2025-03-27T19:07:30.000Z","dependencies_parsed_at":"2024-04-27T20:24:52.161Z","dependency_job_id":"11ef27e6-1372-47f8-8e54-d1fbebd00975","html_url":"https://github.com/john-doherty/swiped-events","commit_stats":{"total_commits":48,"total_committers":10,"mean_commits":4.8,"dds":0.5833333333333333,"last_synced_commit":"d2f10d1f1bc7544ee62102a906e1d1f1225f1e64"},"previous_names":["john-doherty/pure-swipe"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/john-doherty%2Fswiped-events","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/john-doherty%2Fswiped-events/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/john-doherty%2Fswiped-events/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/john-doherty%2Fswiped-events/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/john-doherty","download_url":"https://codeload.github.com/john-doherty/swiped-events/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254319719,"owners_count":22051073,"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":["cordova","html5","hybrid-apps","javascript","no-dependencies","swipe","touch","vanilla-js"],"created_at":"2024-09-24T14:16:45.263Z","updated_at":"2025-05-15T10:06:37.901Z","avatar_url":"https://github.com/john-doherty.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# swiped-events\n\n[![npm](https://img.shields.io/npm/dt/swiped-events)](https://www.npmjs.com/package/swiped-events)\n\nA **1k** script that adds `swiped-left`, `swiped-right`, `swiped-up` and `swiped-down` events to the DOM using [CustomEvent](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent) and pure JS. Based on the StackOverflow thread [Detect a finger swipe through JavaScript on the iPhone and Android](https://stackoverflow.com/questions/2264072/detect-a-finger-swipe-through-javascript-on-the-iphone-and-android)\n\n\u003cimg src=\"docs/example.gif\" height=\"349px\"/\u003e\n\n## Usage\n\nAdd [swiped-events.min.js](dist/swiped-events.min.js) to your page and start listening for swipe events. Events bubble, so you can `addEventListener` at document level, or on individual elements.\n\n### swiped\n\n```js\ndocument.addEventListener('swiped', function(e) {\n  console.log(e.target); // element that was swiped\n  console.log(e.detail); // see event data below\n  console.log(e.detail.dir); // swipe direction\n});\n```\n\n### swiped-left\n\n```js\ndocument.addEventListener('swiped-left', function(e) {\n  console.log(e.target); // element that was swiped\n  console.log(e.detail); // see event data below\n});\n```\n\n### swiped-right\n\n```js\ndocument.addEventListener('swiped-right', function(e) {\n  console.log(e.target); // element that was swiped\n  console.log(e.detail); // see event data below\n});\n```\n\n### swiped-up\n\n```js\ndocument.addEventListener('swiped-up', function(e) {\n  console.log(e.target); // element that was swiped\n  console.log(e.detail); // see event data below\n});\n  ```\n\n### swiped-down\n\n```js\ndocument.addEventListener('swiped-down', function(e) {\n  console.log(e.target); // element that was swiped\n  console.log(e.detail); // see event data below\n});\n```\n\n### event data\n\nThe following event data is included with every event and accessible via `e.detail`\n\n```js\n{\n  dir: 'up',            // swipe direction (up,down,left,right)\n  touchType: 'direct',  // touch type (stylus,direct) - stylus=apple pencil and direct=finger\n  xStart: 196,          // x coords of swipe start\n  fingers: 1,           // number of fingers used\n  xEnd: 230,            // x coords of swipe end\n  yStart: 196,          // y coords of swipe start\n  yEnd: 4               // y coords of swipe end\n}\n```\n\n### Configure\n\nYou can _optionally_ configure how [swiped-events](https://github.com/john-doherty/swiped-events) works using the following HTML attributes:\n\n| Attribute              | Description                                                                          | Type      | Default |\n|------------------------|--------------------------------------------------------------------------------------|-----------|---------|\n| `data-swipe-threshold` | Number of *pixels* or *percent of viewport-axis* a user must move before swipe fires | _integer_ | 20      |\n| `data-swipe-unit`      | *Unit* of the threshold (can be either \"px\", \"vh\" or \"vw\")                           | _string_  | \"px\"    |\n| `data-swipe-timeout`   | Number of *milliseconds* from `touchstart` to `touchend`                             | _integer_ | 500     |\n| `data-swipe-ignore`    | If *true*, swipe events on this element are ignored                                  | _boolean_ | _false_ |\n\nIf you do not provide any attributes, it assumes the following:\n\n```html\n\u003cdiv data-swipe-threshold=\"20\"\n     data-swipe-unit=\"px\"\n     data-swipe-timeout=\"500\"\n     data-swipe-ignore=\"false\"\u003e\n     Swiper, get swiping!\n\u003c/div\u003e\n```\n\nTo set defaults application wide, set config attributes on a parent/topmost element:\n\n```html\n\u003cbody data-swipe-threshold=\"50\" data-swipe-unit=\"vw\" data-swipe-timeout=\"250\"\u003e\n    \u003cdiv\u003eSwipe me\u003c/div\u003e\n    \u003cdiv\u003eor me\u003c/div\u003e\n\u003c/body\u003e\n```\n\n## Contributing\n\n1. Fork it!\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -m 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request\n\n### Development\n\nThe project includes everything needed to tweak, including a node webserver. Run the following, then visit [http://localhost:8080](http://localhost:8080) in your browser.\n\n_You can test on a desktop using [Device Mode](https://developers.google.com/web/tools/chrome-devtools/device-mode/) in Google Chrome._\n\n```bash\ngit clone https://github.com/john-doherty/swiped-events\ncd swiped-events\nnpm install\nnpm start\n```\n\n### Update .min files\n\nTo create a new version of the minified [swiped-events.min.js](dist/swiped-events.min.js) file from source, tweak the version number in `package.json` and run the following:\n\n```bash\nnpm run build\n```\n\n## Star the repo\n\nIf you find this useful, please star the repo. It helps me priorities which OSS issues to tackle first 🙌\n\n## History\n\nFor change-log, check [releases](https://github.com/john-doherty/swiped-events/releases).\n\n## License\n\nLicensed under [MIT License](LICENSE) \u0026copy; [John Doherty](https://twitter.com/mrjohndoherty)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohn-doherty%2Fswiped-events","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohn-doherty%2Fswiped-events","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohn-doherty%2Fswiped-events/lists"}