"Scroll-Triggered Animations (jQuery)"
Bootstrap 4.1.1 Snippet by naimansari

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
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<div class="wrapper">
<div class="block animatable bounceIn">bounceIn</div>
<div class="block animatable bounceInLeft">bounceInLeft</div>
<div class="block animatable bounceInRight">bounceInRight</div>
<div class="block animatable fadeIn">fadeIn</div>
<div class="block animatable fadeInDown">fadeInDown</div>
<div class="block animatable fadeInUp">fadeInUp</div>
<div class="block animatable moveUp">moveUp</div>
<div class="block animatable fadeBgColor">fadeBgColor</div>
<div class="block animatable bounceIn">bounceIn</div>
<div class="block animatable bounceInLeft">bounceInLeft</div>
<div class="block animatable bounceInRight">bounceInRight</div>
<div class="block animatable fadeIn">fadeIn</div>
<div class="block animatable fadeInDown">fadeInDown</div>
<div class="block animatable fadeInUp">fadeInUp</div>
<div class="block animatable moveUp">moveUp</div>
<div class="block animatable fadeBgColor">fadeBgColor</div>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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
.block {
height: 5em;
line-height: 5em;
width: 10em;
background: #464646;
color: #fdfdfd;
text-align: center;
margin: 1em auto;
text-shadow: 0 0 1px #333; /* so one can see fadeBgColor properly */
}
.animatable {
/* initially hide animatable objects */
visibility: hidden;
/* initially pause animatable objects their animations */
-webkit-animation-play-state: paused;
-moz-animation-play-state: paused;
-ms-animation-play-state: paused;
-o-animation-play-state: paused;
animation-play-state: paused;
}
/* show objects being animated */
.animated {
visibility: visible;
-webkit-animation-fill-mode: both;
-moz-animation-fill-mode: both;
-ms-animation-fill-mode: both;
-o-animation-fill-mode: both;
animation-fill-mode: both;
-webkit-animation-duration: 1s;
-moz-animation-duration: 1s;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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
// Trigger CSS animations on scroll.
// Detailed explanation can be found at http://www.bram.us/2013/11/20/scroll-animations/
// Looking for a version that also reverses the animation when
// elements scroll below the fold again?
// --> Check https://codepen.io/bramus/pen/vKpjNP
jQuery(function($) {
// Function which adds the 'animated' class to any '.animatable' in view
var doAnimations = function() {
// Calc current offset and get all animatables
var offset = $(window).scrollTop() + $(window).height(),
$animatables = $('.animatable');
// Unbind scroll handler if we have no animatables
if ($animatables.length == 0) {
$(window).off('scroll', doAnimations);
}
// Check all animatables and animate them if necessary
$animatables.each(function(i) {
var $animatable = $(this);
if (($animatable.offset().top + $animatable.height() - 20) < offset) {
$animatable.removeClass('animatable').addClass('animated');
}
});
};
// Hook doAnimations on scroll, and trigger a scroll
$(window).on('scroll', doAnimations);
$(window).trigger('scroll');
});
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Related: See More


Questions / Comments: