From 852d77de4a50c359f08233bc464e327487ea7ab3 Mon Sep 17 00:00:00 2001 From: honda2 Date: Sat, 28 Dec 2013 17:54:28 +0100 Subject: [PATCH] update jquery.nav.js to handle misordered lists when you need to change order of the list items, for example because of float:right, getPositions will not work corectly, i've patched it to not count on right orders of list items, but order of targets in html --- jquery.nav.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/jquery.nav.js b/jquery.nav.js index abc74ba..daf9d86 100644 --- a/jquery.nav.js +++ b/jquery.nav.js @@ -113,16 +113,16 @@ var self = this; var linkHref; var topPos; - var $target; - + var targets = []; + self.$nav.each(function() { linkHref = self.getHash($(this)); - $target = $('#' + linkHref); - - if($target.length) { - topPos = $target.offset().top; - self.sections[linkHref] = Math.round(topPos) - self.config.scrollOffset; - } + targets.push('#' + linkHref); + }); + $(targets.join(',')).each(function(){ + var $target = $(this); + topPos = $target.offset().top; + self.sections[$target.attr('id')] = Math.round(topPos) - self.config.scrollOffset; }); }, @@ -220,4 +220,4 @@ }); }; -})( jQuery, window , document ); \ No newline at end of file +})( jQuery, window , document );