Created
September 14, 2017 17:51
-
-
Save iiiBird/4ba1e96f18b5bbaab240365d400204f8 to your computer and use it in GitHub Desktop.
Animate css on scroll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ( $(".animL").length > 0 ) { | |
$(".animL").inViewport(function(px){ | |
if(px) { | |
$(this).addClass("animated fadeInLeft") ; | |
var el = $(this).find('.anim-img'); | |
setTimeout(function(el) {el.addClass("animated bounce");}.bind(this, el), 1000); | |
} | |
}); | |
} | |
;(function($, win) { | |
$.fn.inViewport = function(cb) { | |
return this.each(function(i,el){ | |
function visPx(){ | |
var H = $(this).height(), | |
r = el.getBoundingClientRect(), t=r.top, b=r.bottom; | |
return cb.call(el, Math.max(0, t>0? H-t : (b<H?b:H))); | |
} visPx(); | |
$(win).on("resize scroll", visPx); | |
}); | |
}; | |
}(jQuery, window)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment