From 1ba6f48ea1880b8fc315f6430d296a3ec644ccde Mon Sep 17 00:00:00 2001 From: Simon McClive Date: Thu, 23 Apr 2015 09:12:24 +0100 Subject: [PATCH] Adding support for bounded tick marks between the top of the page and an element in the DOM. --- jquery.scrolldepth.js | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/jquery.scrolldepth.js b/jquery.scrolldepth.js index c30873f..52f0df7 100644 --- a/jquery.scrolldepth.js +++ b/jquery.scrolldepth.js @@ -14,15 +14,16 @@ percentage: true, userTiming: true, pixelDepth: true, - nonInteraction: true + nonInteraction: true, + bottomElement: '' }; var $window = $(window), - cache = [], - lastPixelDepth = 0, - universalGA, - classicGA, - standardEventHandler; + cache = [], + lastPixelDepth = 0, + universalGA, + classicGA, + standardEventHandler; /* * Plugin @@ -228,15 +229,11 @@ * account for dynamic DOM changes. */ - var docHeight = $(document).height(), - winHeight = window.innerHeight ? window.innerHeight : $window.height(), - scrollDistance = $window.scrollTop() + winHeight, - - // Recalculate percentage marks - marks = calculateMarks(docHeight), - - // Timing - timing = +new Date - startTime; + var docHeight = options.bottomElement ? $(options.bottomElement).offset().top : $(document).height(), + winHeight = window.innerHeight ? window.innerHeight : $window.height(), + scrollDistance = $window.scrollTop() + winHeight, + marks = calculateMarks(docHeight), + timing = +new Date - startTime; // If all marks already hit, unbind scroll event if (cache.length >= 4 + options.elements.length) { @@ -257,4 +254,4 @@ }; -})( jQuery, window, document ); +})( jQuery, window, document ); \ No newline at end of file