Skip to content

Instantly share code, notes, and snippets.

@iiiBird
Created September 14, 2017 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iiiBird/4ba1e96f18b5bbaab240365d400204f8 to your computer and use it in GitHub Desktop.
Save iiiBird/4ba1e96f18b5bbaab240365d400204f8 to your computer and use it in GitHub Desktop.
Animate css on scroll
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