$(function () { function getobjtop(obj) { var obj = $(obj); return obj.offset().top; } function addanimateclass(obj) { var obj = $(obj); obj.each(function () { var $this = $(this); var top = getobjtop($this); top = parsefloat(top); top = isnan(top) ? 0 : top; var scrolltop = $(window).scrolltop(); var w_height = $(window).height(); var name = $this.attr("animate-name"); var delay = parseint($this.attr("animate-delay")); delay = isnan(delay) ? 0 : delay; if (name && (scrolltop + w_height) > (top - 10)) { if (delay > 0) { settimeout(function () { $this.addclass(name); }, delay); } else { $this.addclass(name); } } }); } var arr = [ "*" ]; function addclass() { arr.foreach(function (value, callbackfen, arr) { addanimateclass(value); }); } addclass(); $(window).scroll(addclass); });