{"id":13397592,"url":"https://github.com/mciastek/sal","last_synced_at":"2025-05-14T04:09:58.119Z","repository":{"id":37617223,"uuid":"105066903","full_name":"mciastek/sal","owner":"mciastek","description":"🚀 Performance focused, lightweight scroll animation library 🚀","archived":false,"fork":false,"pushed_at":"2023-01-07T04:11:22.000Z","size":1726,"stargazers_count":3630,"open_issues_count":41,"forks_count":178,"subscribers_count":49,"default_branch":"master","last_synced_at":"2025-05-12T09:44:01.697Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://mciastek.github.io/sal/","language":"HTML","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/mciastek.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":"2017-09-27T20:37:38.000Z","updated_at":"2025-05-12T08:58:22.000Z","dependencies_parsed_at":"2023-02-06T11:30:55.999Z","dependency_job_id":null,"html_url":"https://github.com/mciastek/sal","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mciastek%2Fsal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mciastek%2Fsal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mciastek%2Fsal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mciastek%2Fsal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mciastek","download_url":"https://codeload.github.com/mciastek/sal/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254070109,"owners_count":22009559,"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":[],"created_at":"2024-07-30T18:01:33.323Z","updated_at":"2025-05-14T04:09:58.079Z","avatar_url":"https://github.com/mciastek.png","language":"HTML","funding_links":[],"categories":["HTML","Uncategorized","Animate on scroll"],"sub_categories":["Uncategorized"],"readme":"# Sal [![npm version](https://badge.fury.io/js/sal.js.svg)](https://www.npmjs.com/package/sal.js) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/mciastek/sal/blob/master/LICENSE) [![Build Status](https://travis-ci.com/mciastek/sal.svg?branch=master)](https://travis-ci.com/mciastek/sal)\n\nPerformance focused, lightweight (less than **2.8 kb**) scroll animation library, written in vanilla JavaScript. No dependencies!\n\n**Sal** (_Scroll Animation Library_) was created to provide a performant and lightweight solution for animating elements on scroll. It's based on the [Intersection Observer](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API), which gives amazing performance in terms of checking the element's presence in the viewport.\n\n**Note:** Intersection Observer API is an experimental technology so be sure to consult the [browser compatibility table](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#Browser_compatibility) and consider using a [polyfill](https://github.com/w3c/IntersectionObserver/tree/master/polyfill).\n\n## Table of Contents\n- [Install](#install)\n- [Usage](#usage)\n- [Animations](#animations)\n- [Options](#options)\n- [API](#api)\n- [Events](#events)\n- [Misc](#misc)\n- [License](#license)\n\n## Install\n\n```sh\n# Usage with NPM\n$ npm install --save sal.js\n\n# and with Yarn\n$ yarn add sal.js\n```\n\nLoad it with your favorite module loader or use as a global variable\n\n```js\n// ES6 modules\nimport sal from 'sal.js'\n\n// CommonJS modules\nvar sal = require('sal.js')\n```\n\nAnd remember to add styles\n\n```scss\n// Webpack\n@import '~sal.js/sal.css';\n\n// Other\n@import './node_modules/sal.js/dist/sal.css';\n```\n\n## Usage\n\nIn HTML, add a `data-sal` attribute with the animation name as value, e.g.:\n\n```html\n\u003cdiv data-sal=\"fade\"\u003e\u003c/div\u003e\n```\n\nThen simply initialize Sal in your script file:\n\n```js\nsal();\n```\n\nIt will look for all elements with a `data-sal` attribute and launch their animation when in viewport.\n\n## Animations\nIn **sal.js** you can easily change animation's options, by adding a proper `data` attribute:\n- `data-sal-duration` - changes duration of the animation (from 200 to 2000 ms)\n- `data-sal-delay` - adds delay to the animation (from 5 to 1000 ms)\n- `data-sal-easing` - sets easing for the animation (see [easings.net](https://easings.net/) for reference)\n\nFor example:\n```html\n\u003cdiv\n  data-sal=\"slide-up\"\n  data-sal-delay=\"300\"\n  data-sal-easing=\"ease-out-back\"\n\u003e\u003c/div\u003e\n```\n\nThe library supports several animations:\n- `fade`\n- `slide-up`\n- `slide-down`\n- `slide-left`\n- `slide-right`\n- `zoom-in`\n- `zoom-out`\n- `flip-up`\n- `flip-down`\n- `flip-left`\n- `flip-right`\n\n### Duration and delay\n\nAdditionaly, when you want to customise animation's properties - `duration`, `delay` and `easing`, you can use [CSS variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties) to set any value you want. See the following example:\n\n```html\n\u003cdiv\n  data-sal=\"slide-up\"\n  style=\"--sal-duration: 3s; --sal-delay: 2s;\"\n\u003e\u003c/div\u003e\n```\n\nSupported custom properties:\n  - `--sal-duration`\n  - `--sal-delay`\n  - `--sal-easing`\n\nRemember, that you can use only data attributes (e.g. `data-sal-delay`) or CSS custom properties (e.g. `--sal-delay`). Data attributes have precedence over CSS custom properties.\n\n### Repeating animation\n\nBy default every animation is played once. You can change it by setting `once` option to `false` (see [Options](#options)). What's more, it's possible to override this option for an animated element by adding one of the following attributes:\n- `data-sal-repeat` - forces animation replay\n- `data-sal-once` - plays animation once\n\n## Options\n\n| Property | Type | Description | Default  |\n|---------------------------|-------------|---------------|---------|\n| `threshold` | Number | Percentage of an element's area that needs to be visible to launch animation (see [docs](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/thresholds)) | `0.5` |\n| `once` | Boolean | Defines if animation needs to be launched once. Can be overridden, see [Repeating Animation](#repeating-animation). | `true` |\n| `disabled` | Boolean or Function | Flag (or a function returning boolean) for disabling animations | `false` |\n\nYou can set options during Sal's initialization, e.g.:\n\n```js\nsal({\n  threshold: 1,\n  once: false,\n});\n```\n\n### Advanced options\n\n| Property | Type | Description | Default  |\n|---------------------------|-------------|---------------|---------|\n| `root` | Element or null | The element that is used as the viewport for checking visibility of the target (see [docs](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/root)) | `window` |\n| `selector` | String | Selector of the elements to be animated | `[data-sal]` |\n| `animateClassName` | String | Class name which triggers animation | `sal-animate` |\n| `disabledClassName` | String | Class name which defines the disabled state | `sal-disabled` |\n| `rootMargin` | String | Corresponds to root's bounding box margin (see [docs](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/rootMargin)) | `0% 50%` |\n| `enterEventName` | String | Enter event name (see [Events](#events)) | `sal:in` |\n| `exitEventName` | String | Exit event name (see [Events](#events)) | `sal:out` |\n\n## API\n\n| Method name | Description |\n|---------------------------|-------------|\n| `enable` | Enables animations |\n| `disable` | Disables animations |\n| `reset` | Resets instance and allows to pass new options (see [Options](#options)) |\n| `update` | Updates observer with new elements to animated. Useful for dynamically injected HTML. |\n\nPublic methods are available after Sal's initialization:\n\n```js\nconst scrollAnimations = sal();\n\nscrollAnimations.disable();\n```\n\n### Changing options after intialization\n\nIf you want to change Sal's options once it's been initialized, you should use `reset` method, that allows you to pass new set of options. It can be useful, when you would like to provide different options for specific viewport sizes.\n\n```js\nconst scrollAnimations = sal();\n\n// Provide new options\nscrollAnimations.reset({\n  selector: 'animated-element',\n  once: true,\n});\n```\n\n## Events\n\nThis library supports events, fired when element is entering or exiting viewport (they are named `sal:in` and `sal:out` by default). Property `detail` is [IntersectionObserverEntry](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserverEntry) object.\n\n\nYou can attach listener to specific element.\n\n```js\n// Get element with \".animated\" class, which has \"data-sal\" attribute\nconst element = document.querySelector('.animated');\n\nelement.addEventListener('sal:in', ({ detail }) =\u003e {\n  console.log('entering', detail.target);\n});\n```\n\nor to the whole document\n\n```js\ndocument.addEventListener('sal:out', ({ detail }) =\u003e {\n  console.log('exiting', detail.target);\n});\n```\n\n**Note:** This library uses [Custom Event](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent) to trigger events on animated elements. Check the [compatibility table](https://caniuse.com/#search=custom%20event) to know if your browser supports it and use a [polyfill](https://github.com/kumarharsh/custom-event-polyfill) if needed.\n\n## Misc\n\n### No-JS support\n\nIf you aim to support users that don't allow sites to use JavaScript, you should consider disabling animations' styles in the first place. You can use `\u003cnoscript /\u003e` element to inject required CSS. Here's an example:\n\n```html\n\u003cnoscript\u003e\n  \u003cstyle type=\"text/css\"\u003e\n    [data-sal|='fade'] {\n      opacity: 1;\n    }\n\n    [data-sal|='slide'],\n    [data-sal|='zoom'] {\n      opacity: 1;\n      transform: none;\n    }\n\n    [data-sal|='flip'] {\n      transform: none;\n    }\n  \u003c/style\u003e\n\u003c/noscript\u003e\n```\n\n## License\n\nCreated by [Mirek Ciastek](https://github.com/mciastek). Released under the [MIT License](https://github.com/mciastek/sal/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmciastek%2Fsal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmciastek%2Fsal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmciastek%2Fsal/lists"}