forked from robflaherty/scroll-depth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.scrolldepth.min.js
1 lines (1 loc) · 1.06 KB
/
jquery.scrolldepth.min.js
1
(function(a,b,c,d){"use strict";var e={elements:[],minHeight:0,offset:0,percentage:!0,testing:!1},f=a(b),g=[];a.scrollDepth=function(d){function i(b,c,e){d.testing?a("#console").html(b+": "+c):(_gaq.push(["_trackEvent","Scroll Depth",b,c,1,!0]),arguments.length>2&&_gaq.push(["_trackTiming","Scroll Depth",b,e,c,100]))}function j(a){return{"25%":parseInt(a*.25,10),"50%":parseInt(a*.5,10),"75%":parseInt(a*.75,10),"100%":a-1}}function k(b,c,d){a.each(b,function(b,e){a.inArray(b,g)===-1&&c>=e&&(i("Percentage",b,d),g.push(b))})}function l(b,c,d){a.each(b,function(b,e){a.inArray(e,g)===-1&&a(e).length&&c>=a(e).offset().top&&(i("Elements",e,d),g.push(e))})}var h=+(new Date);d=a.extend({},e,d);if(a(c).height()<d.minHeight)return;i("Percentage","Baseline"),f.bind("scroll.scrollDepth",function(){var e=a(c).height(),i=b.innerHeight?b.innerHeight:f.height(),m=f.scrollTop()+i,n=parseInt(i*(d.offset/100),10),o=j(e),p=+(new Date)-h;if(g.length>=4+d.elements.length){f.unbind("scroll.scrollDepth");return}d.elements&&l(d.elements,m,p),d.percentage&&k(o,m,p)})}})(jQuery,window,document)