-
Notifications
You must be signed in to change notification settings - Fork 0
/
animated-1.0.0.js
54 lines (43 loc) · 1.25 KB
/
animated-1.0.0.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
Name: Animated
Version: 1.0.0
Description: Script that uses animate.css on scroll
Created on: 2016-02-29
Author: Artur Stępień ([email protected])
Author URI: http://www.bestproject.pl
Copyrights: BestProject
License: GNU GPL 3.0 (See LICENSE file)
Requires: animated.css and jQuery
How to use: See example.html
*/
(function ($) {
$.fn.Animated = function () {
var $window = $(window);
$window.on('scroll', revealOnScroll);
function revealOnScroll() {
var win_height_padded = $window.height() * 1.1;
var scrolled = $window.scrollTop(),
win_height_padded = $window.height() * 1.1;
// Showed...
$('[class*="animated-"]').each(function () {
var $this = $(this);
var offsetTop = $this.offset().top;
if (scrolled + win_height_padded > offsetTop) {
$this[0].className = $this[0].className.replace('animated-','animated ');
}
});
// Hidden...
$(".animated").each(function (index) {
var $this = $(this);
var offsetTop = $this.offset().top;
if (scrolled + win_height_padded < offsetTop) {
$this[0].className = $this[0].className.replace('animated ','animated-');
}
});
}
setTimeout(function(){
revealOnScroll();
}, 100);
return this;
};
}(jQuery));