jquery - One page prev/next navigation based on list/anchor links -
after finished laughing @ attempt modify jquery me with:
what happen is:
to left 2 visible buttons prev/next hide other li's. prev button work , go previous anchor , next going next anchor.
or going wrong way... open better suggestions.
thanks
only modified few parts:
first, keep 2 buttons:
<li><a href="#prev" class="scroll">prev</a></li> <li><a href="#next" class="scroll">next</a></li>
next, keep track of different anchors, , 1 active:
var anchors = ['anchortop', 'anchorone', 'anchortwo', 'anchorthree', 'anchorfour', 'anchorfive']; var currentidx = 0;
finally, either decrement or increment currentidx depending on button clicked , section at:
var full_url = this.href, parts = full_url.split('#'), btn = parts[1]; if (btn == 'prev' && currentidx > 0) { currentidx--; } else if (btn == 'next' && currentidx < anchors.length - 1) { currentidx++; } var trgt = anchors[currentidx], target_offset = $('#' + trgt).offset(), target_top = target_offset.top;
Comments
Post a Comment