-
Notifications
You must be signed in to change notification settings - Fork 1
/
jquery.scransition.js
37 lines (33 loc) · 982 Bytes
/
jquery.scransition.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
/* Scransition jQuery plugin
* Animate CSS with a transition when you scroll an item into the viewport by removing a class from it
* Author: Scott Nelle
* Usage:
* CSS: h2.scransition { opacity: 0; };
* JavaScript: $('h2').scransition();
* Available Parameters: { transition:'0.4s', offset:150 }
**/
(function ( $ ) {
$.fn.scransition = function(options) {
var defaults = {
transition: '0.4s',
offset: 150,
};
var settings = $.extend( {}, defaults, options );
var els = this;
// set up initial state
this.each(function(){
$(this).addClass('scransition')
.css('transition',settings.transition)
.css('-webkit-transition',settings.transition);
});
// remove class when image shows up on the page
$(window).scroll(function() {
els.each(function(){
if ($(window).scrollTop() + $(window).height() > $(this).offset().top + settings.offset) {
$(this).removeClass('scransition');
}
});
});
return this;
};
}( jQuery ));