{"id":13638724,"url":"https://github.com/oom-components/carousel","last_synced_at":"2025-05-14T16:32:41.174Z","repository":{"id":38814376,"uuid":"93303966","full_name":"oom-components/carousel","owner":"oom-components","description":"Yet another carousel","archived":false,"fork":false,"pushed_at":"2022-06-23T16:35:22.000Z","size":98,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-28T10:57:13.628Z","etag":null,"topics":["carousel","custom-elements-v1","es6","progressive-enhancement","slider","vanilla-javascript"],"latest_commit_sha":null,"homepage":"https://oom-components.github.io/carousel/demo/","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/oom-components.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2017-06-04T09:43:41.000Z","updated_at":"2025-01-13T18:08:21.000Z","dependencies_parsed_at":"2022-09-18T09:11:14.351Z","dependency_job_id":null,"html_url":"https://github.com/oom-components/carousel","commit_stats":null,"previous_names":["progressive-web-components/carousel","progressive-web-components/carrousel"],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oom-components%2Fcarousel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oom-components%2Fcarousel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oom-components%2Fcarousel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oom-components%2Fcarousel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oom-components","download_url":"https://codeload.github.com/oom-components/carousel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254183217,"owners_count":22028450,"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":["carousel","custom-elements-v1","es6","progressive-enhancement","slider","vanilla-javascript"],"created_at":"2024-08-02T01:00:52.491Z","updated_at":"2025-05-14T16:32:40.895Z","avatar_url":"https://github.com/oom-components.png","language":"JavaScript","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"readme":"# @oom/carousel\n\nCarousel with the following features:\n\n- No dependencies\n- Light: Less than 200 lines of code (including comments and spaces)\n- Follows the **progressive enhancement strategy:**\n  - Works with just `html`\n  - Works better with `html` and `css`\n  - Works much better with `html`, `css` and `js`\n  - Works much much better when `js` polyfills are not needed\n- High performance: Use native scroll to move the elements.\n- No need to wait for javascript to build the carousel.\n- No styles or themes are provided with this package. You decide how the\n  carousel must look.\n- Support for touch devices\n- Support for keyboard\n- Build with modern javascript, using ES6 modules and custom elements\n\n## Install\n\nRequirements:\n\n- NPM or Yarn to install\n  [the package](https://www.npmjs.com/package/@oom/carousel)\n- It's recommended to use\n  [the Scroll Behaviour polyfill](https://github.com/iamdustan/smoothscroll) to\n  [have better support for more browsers](https://caniuse.com/#feat=css-scroll-behavior)\n- For browsers\n  [not supporting custom elements](https://caniuse.com/#feat=custom-elementsv1),\n  [you can use this polyfill](https://github.com/webcomponents/custom-elements)\n\n```sh\nnpm install @oom/carousel\nnpm install smoothscroll-polyfill\nnpm install @webcomponents/custom-elements\n```\n\n## Usage\n\n### HTML\n\nLet's start with the following html code:\n\n```html\n\u003cmy-carousel role=\"region\" aria-label=\"Gallery\" tabindex=\"0\"\u003e\n    \u003cdiv\u003e\u003cimg src=\"http://placehold.it/500x300\"\u003e\u003c/div\u003e\n    \u003cdiv\u003e\u003cimg src=\"http://placehold.it/500x300\"\u003e\u003c/div\u003e\n    \u003cdiv\u003e\u003cimg src=\"http://placehold.it/500x300\"\u003e\u003c/div\u003e\n    \u003cdiv\u003e\u003cimg src=\"http://placehold.it/500x300\"\u003e\u003c/div\u003e\n    \u003cdiv\u003e\u003cimg src=\"http://placehold.it/500x300\"\u003e\u003c/div\u003e\n    \u003cdiv\u003e\u003cimg src=\"http://placehold.it/500x300\"\u003e\u003c/div\u003e\n    \u003cdiv\u003e\u003cimg src=\"http://placehold.it/500x300\"\u003e\u003c/div\u003e\n    \u003cdiv\u003e\u003cimg src=\"http://placehold.it/500x300\"\u003e\u003c/div\u003e\n    \u003cdiv\u003e\u003cimg src=\"http://placehold.it/500x300\"\u003e\u003c/div\u003e\n    \u003cdiv\u003e\u003cimg src=\"http://placehold.it/500x300\"\u003e\u003c/div\u003e\n\u003c/my-carousel\u003e\n\n\u003cbutton class=\"carousel-next\"\u003ePrevious\u003c/button\u003e\n\u003cbutton class=\"carousel-prev\"\u003eNext\u003c/button\u003e\n```\n\n### CSS\n\nUse css to define the carousel appearance:\n\n```css\nmy-carousel {\n    overflow-x: scroll;\n    display: flex;\n    scroll-snap-type: x mandatory;\n    -webkit-overflow-scrolling: touch;\n}\nmy-carousel \u003e div {\n    flex: 0 0 auto;\n    scroll-snap-align: center;\n}\n```\n\n### JS\n\nAnd finally use javascript for a complete experience:\n\n```js\nimport Carousel from \"./carousel/carousel.js\";\n\n//Register the custom element\ncustomElements.define(\"my-carousel\", Carousel);\n\n//Select the carousel\nconst carousel = document.querySelector(\"my-carousel\");\n\n//Navigate\ndocument.querySelector(\".carousel-next\").addEventListener(\n  \"click\",\n  (event) =\u003e carousel.index += 1,\n);\ndocument.querySelector(\".carousel-prev\").addEventListener(\n  \"click\",\n  (event) =\u003e carousel.index -= 1,\n);\n```\n\n## Player\n\nUse the module `player` to create a player and init a slideshow. Example:\n\n```js\nimport Player from \"./carousel/player.js\";\n\nconst player = new Player(carousel);\n\n//Start the slideshow\nplayer.play();\n\n//Start the slideshow with 10 seconds to wait between slides\nplayer.play(10000);\n\n//Stop\nplayer.stop();\n```\n\n## API\n\nThis is a custom element that extends `HtmlElement`, so it innerit the same api\nof a standard html element with the following additions:\n\n```js\n//Get/set the slide index\ncarousel.index = 3; //move to the slide 3\nconst currIndex = carousel.index; //get the current slide index\ncarousel.index += 1; //move to the next slide\ncarousel.index -= 1; //move to the previous slide\n\n//Move the slide using scroll\n\nlet atBeginning = carousel.scrollFromLeft === 0; //Determine whether the scroll is at begining\nlet atTheEnd = carousel.scrollFromRight === 0; //Determine whether the scroll is at the end\n\ncarousel.scrollFromLeft = 0; //Performs a scroll to the beginning\ncarousel.scrollFromRight = 0; //Performs a scroll to the end\ncarousel.next(); //Move the scroll to next\ncarousel.prev(); //Move the scroll to previous\n```\n\n## Demo and tests\n\n- Demo: https://oom-components.github.io/carousel/demo\n- Tests: https://oom-components.github.io/carousel/tests\n\nTo run the demo locally, just clone this repository, enter in the directory and\nexecute:\n\n```sh\nnpm install\nnpm start\n```\n\nYou should see something in the following urls:\n\n- Demo: `http://localhost:8080/demo`\n- Test: `http://localhost:8080/tests`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foom-components%2Fcarousel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foom-components%2Fcarousel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foom-components%2Fcarousel/lists"}