Skip to content

Commit 47936eb

Browse files
committed
Initial commit
0 parents  commit 47936eb

File tree

4 files changed

+139
-0
lines changed

4 files changed

+139
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require('./src/css/animations.css');
2+
3+
let elements = [];
4+
5+
const elementIsOnScreen = function (element) {
6+
let rect = element.getBoundingClientRect();
7+
let elemTop = rect.top + 100;
8+
let elemBottom = rect.bottom;
9+
return elemTop < window.innerHeight && elemBottom >= 0;
10+
}
11+
12+
const handleAnimations = function () {
13+
elements = Array.from(document.getElementsByClassName('vue-animations'));
14+
for (let i = 0; i < elements.length; i++) {
15+
let elem = elements[i];
16+
if (!elem.classList.contains('applied') && elementIsOnScreen(elem)) {
17+
elem.classList.add('applied');
18+
}
19+
}
20+
}
21+
22+
document.addEventListener('scroll', handleAnimations);
23+
module.exports = {}

package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"private": "true",
3+
"name": "vue-animations",
4+
"version": "0.0.1",
5+
"description": "A simple vue package with some animation classes to fade elements in",
6+
"main": "index.js",
7+
"scripts": {
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "git+https://github.com/vollborn/vue-animations.git"
13+
},
14+
"keywords": [
15+
"animations",
16+
"effects",
17+
"vue"
18+
],
19+
"author": "Oliver Vollborn",
20+
"license": "MIT",
21+
"bugs": {
22+
"url": "https://github.com/vollborn/vue-animations/issues"
23+
},
24+
"homepage": "https://github.com/vollborn/vue-animations#readme"
25+
}

src/css/animations.css

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
Animations
3+
*/
4+
5+
.vue-animations.fade-in {
6+
opacity: 0;
7+
transition: 0.3s ease-in;
8+
}
9+
10+
.vue-animations.fade-from-left {
11+
opacity: 0;
12+
transform: translate(-30px, 0);
13+
transition: 0.5s ease-out;
14+
}
15+
16+
.vue-animations.fade-from-right {
17+
opacity: 0;
18+
transform: translate(30px, 0);
19+
transition: 0.5s ease-out;
20+
}
21+
22+
.vue-animations.size-fade-in {
23+
opacity: 0;
24+
transform: scale(0.8, 0.8);
25+
transition: 0.5s ease-out;
26+
}
27+
28+
.vue-animations.draw-to-right {
29+
width: 0;
30+
transition: 0.5s ease-in-out;
31+
}
32+
33+
/*
34+
Applied
35+
*/
36+
37+
.vue-animations.applied.fade-in {
38+
opacity: 1;
39+
}
40+
41+
.vue-animations.applied.fade-from-left {
42+
opacity: 1;
43+
transform: none;
44+
}
45+
46+
.vue-animations.applied.fade-from-right {
47+
opacity: 1;
48+
transform: none;
49+
}
50+
51+
.vue-animations.applied.size-fade-in {
52+
opacity: 1;
53+
transform: none;
54+
}
55+
56+
.vue-animations.applied.draw-to-right {
57+
width: 100%;
58+
}
59+
60+
@media only screen and (max-width: 800px) {
61+
.vue-animations.fade-in,
62+
.vue-animations.fade-from-left,
63+
.vue-animations.fade-from-right {
64+
opacity: 0;
65+
transition: 0.3s ease-in;
66+
transform: unset;
67+
}
68+
69+
.vue-animations.applied.fade-in,
70+
.vue-animations.applied.fade-from-left,
71+
.vue-animations.applied.fade-from-right {
72+
opacity: 1;
73+
}
74+
}
75+
76+
/*
77+
Additions
78+
*/
79+
80+
.delay-1 {
81+
transition-delay: 0.3s;
82+
}
83+
84+
.delay-2 {
85+
transition-delay: 0.6s;
86+
}
87+
88+
.delay-3 {
89+
transition-delay: 0.9s;
90+
}

0 commit comments

Comments
 (0)