├── .gitignore ├── CHANGELOG.md ├── rollup.config.js ├── LICENSE ├── src └── index.js ├── package.json ├── README.md └── .eslintrc.json /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | index.js 4 | !src/index.js 5 | module.js -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # svelte-transitions-slide changelog 2 | 3 | ## 1.0.0 4 | 5 | * First release -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import buble from 'rollup-plugin-buble'; 2 | 3 | const pkg = require('./package.json'); 4 | 5 | export default { 6 | entry: 'src/index.js', 7 | plugins: [buble()], 8 | external: ['eases-jsnext'], 9 | targets: [ 10 | { dest: pkg.main, format: 'cjs' }, 11 | { dest: pkg.module, format: 'es' } 12 | ] 13 | }; 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017 [these people](https://github.com/sveltejs/svelte-transitions-fade/graphs/contributors) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import { cubicOut } from 'eases-jsnext'; 2 | 3 | export default function slide( 4 | node, 5 | { delay = 0, duration = 400, easing = cubicOut } 6 | ) { 7 | const style = getComputedStyle(node); 8 | const opacity = +style.opacity; 9 | const height = parseFloat(style.height); 10 | const paddingTop = parseFloat(style.paddingTop); 11 | const paddingBottom = parseFloat(style.paddingBottom); 12 | const marginTop = parseFloat(style.marginTop); 13 | const marginBottom = parseFloat(style.marginBottom); 14 | const borderTopWidth = parseFloat(style.borderTopWidth); 15 | const borderBottomWidth = parseFloat(style.borderBottomWidth); 16 | 17 | return { 18 | delay, 19 | duration, 20 | easing, 21 | css: t => 22 | `overflow: hidden;` + 23 | `opacity: ${Math.min(t * 20, 1) * opacity};` + 24 | `height: ${t * height}px;` + 25 | `padding-top: ${t * paddingTop}px;` + 26 | `padding-bottom: ${t * paddingBottom}px;` + 27 | `margin-top: ${t * marginTop}px;` + 28 | `margin-bottom: ${t * marginBottom}px;` + 29 | `border-top-width: ${t * borderTopWidth}px;` + 30 | `border-bottom-width: ${t * borderBottomWidth}px;` 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "svelte-transitions-slide", 3 | "version": "1.0.0", 4 | "description": "Slide transition plugin for Svelte", 5 | "main": "index.js", 6 | "module": "module.js", 7 | "scripts": { 8 | "test": "echo \"Error: no test specified\" && exit 1", 9 | "build": "rollup -c", 10 | "prepublish": "npm run lint && npm run build", 11 | "lint": "eslint src" 12 | }, 13 | "files": [ 14 | "index.js", 15 | "module.js" 16 | ], 17 | "repository": { 18 | "type": "git", 19 | "url": "git+https://github.com/sveltejs/svelte-transitions-slide.git" 20 | }, 21 | "keywords": [ 22 | "svelte", 23 | "transitions", 24 | "css", 25 | "animation" 26 | ], 27 | "author": "Rich Harris", 28 | "license": "MIT", 29 | "bugs": { 30 | "url": "https://github.com/sveltejs/svelte-transitions-slide/issues" 31 | }, 32 | "homepage": "https://github.com/sveltejs/svelte-transitions-slide#readme", 33 | "devDependencies": { 34 | "eslint": "^3.19.0", 35 | "eslint-plugin-import": "^2.2.0", 36 | "rollup": "^0.41.6", 37 | "rollup-plugin-buble": "^0.15.0" 38 | }, 39 | "dependencies": { 40 | "eases-jsnext": "^1.0.9" 41 | } 42 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## DEPRECATED — As of Svelte v3, transitions are built into the main package 2 | 3 | # svelte-transitions-slide 4 | 5 | Slide transition plugin for [Svelte](https://svelte.technology). [Demo](https://svelte.technology/repl?version=2.5.0&gist=b447904fdd05737538c24268cca144cc) 6 | 7 | ![slide-hello](https://cloud.githubusercontent.com/assets/1162160/25782611/50b10200-331c-11e7-9cd9-9ce8cbaf3f33.gif) 8 | 9 | Note that this transition will behave oddly with `display: inline` elements. 10 | 11 | ## Usage 12 | 13 | Recommended usage is via [svelte-transitions](https://github.com/sveltejs/svelte-transitions), but you can use this module directly if you prefer. Note that it assumes an ES module or CommonJS environment. 14 | 15 | Install with npm or yarn: 16 | 17 | ```bash 18 | npm install --save svelte-transitions-slide 19 | ``` 20 | 21 | Then add the plugin to your Svelte component's exported definition: 22 | 23 | ```html 24 | 27 | 28 | {#if visible} 29 | 30 |
hello!
31 | {/if} 32 | 33 | 40 | ``` 41 | 42 | 43 | ## Parameters 44 | 45 | You can specify `delay` and `duration` parameters, which default to `0` and `400` respectively, and a custom `easing` function (which should live on your `helpers`): 46 | 47 | ```html 48 |
49 | slides in slowly 50 |
51 | 52 | 61 | ``` 62 | 63 | 64 | ## License 65 | 66 | [MIT](LICENSE) 67 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "rules": { 4 | "indent": [ 5 | 2, 6 | "tab", 7 | { 8 | "SwitchCase": 1 9 | } 10 | ], 11 | "semi": [ 12 | 2, 13 | "always" 14 | ], 15 | "keyword-spacing": [ 16 | 2, 17 | { 18 | "before": true, 19 | "after": true 20 | } 21 | ], 22 | "space-before-blocks": [ 23 | 2, 24 | "always" 25 | ], 26 | "no-mixed-spaces-and-tabs": [ 27 | 2, 28 | "smart-tabs" 29 | ], 30 | "no-cond-assign": 0, 31 | "no-unused-vars": 2, 32 | "object-shorthand": [ 33 | 2, 34 | "always" 35 | ], 36 | "no-const-assign": 2, 37 | "no-class-assign": 2, 38 | "no-this-before-super": 2, 39 | "no-var": 2, 40 | "no-unreachable": 2, 41 | "valid-typeof": 2, 42 | "quote-props": [ 43 | 2, 44 | "as-needed" 45 | ], 46 | "one-var": [ 47 | 2, 48 | "never" 49 | ], 50 | "prefer-arrow-callback": 2, 51 | "prefer-const": [ 52 | 2, 53 | { 54 | "destructuring": "all" 55 | } 56 | ], 57 | "arrow-spacing": 2, 58 | "no-inner-declarations": 0 59 | }, 60 | "env": { 61 | "es6": true, 62 | "browser": true, 63 | "node": true, 64 | "mocha": true 65 | }, 66 | "extends": [ 67 | "eslint:recommended", 68 | "plugin:import/errors", 69 | "plugin:import/warnings" 70 | ], 71 | "parserOptions": { 72 | "ecmaVersion": 6, 73 | "sourceType": "module" 74 | }, 75 | "settings": { 76 | "import/core-modules": [ 77 | "svelte" 78 | ] 79 | } 80 | } --------------------------------------------------------------------------------