jquery - Trigger a function on multiple elements on scroll -
i’m trying trigger odometer.js on several figures on scroll. code wrong , think i’m gonna cry.. 2 hours , nothing : uncaught typeerror: this.el.appendchild not function...
please help. thanks.
html:
<h2 class="odometre" chiffre-cle="2000">0</h2> <h2 class="odometre" chiffre-cle="2000">0</h2> <h2 class="odometre" chiffre-cle="2000">0</h2>
javascript:
var y = $(window).height(); var coord = y / 2; $(window).scroll(function(){ if($(window).scrolltop() > coord){ $(".odometre").each(function(){ var el = $(this); var chiffre = el.attr("chiffre-cle"); od = new odometer({ el: el, value: 0, format: 'd', animation: 'ease', duration: 400 }); od.update(chiffre); }) } else { } });
looks odometer.js needing htmlelement not jquery object, in order fix should remove $()
wrapper this
right here:
var el = $(this); var chiffre = el.attr("chiffre-cle");
to make like:
var el = this; var chiffre = $(el).attr("chiffre-cle");
Comments
Post a Comment