javascript - Scroll to NEXT/PREV buttons with Bootstrap ScrollSpy -


i looking through answers creating next , prev buttons go through anchor points on page, couldn't find need. 1 might of been close wanted decided use starting point: how can make link go next anchor on page without knowing anchor name?

i created fiddle concept presented in answer , tried make work bootstrap's scrollspy (detects current section , anchor).

i have gotten far: http://jsfiddle.net/gukne0ol/2/

$('.next').click(function (e) {     e.preventdefault();     var current_anchor = $('li.active a');     var next_anchor = current.next('li a');     $('body').animate({         scrolltop: next_anchor.offset().top     }); })  $('.previous').click(function (e) {     e.preventdefault();     var current_anchor = $('li.active a');     var previous_anchor = current.prev('li a');     $('body').animate({         scrolltop: previous_anchor.offset().top     }); }) 

the original answer targets <a> tag, in bootstrap's scrollspy, adds active class <li> tag wrapping <a> tag. changed accordingly... feel it's close? can't tell...

can help? thank you!

target active li, find previous/next li, , drill down anchor.

http://jsfiddle.net/gukne0ol/9/

// activate bootstrap scrollspy $('body').scrollspy({      target: '.navbar' })  $('.next').click(function (e) {       var next = $('.navbar ul li.active').next().find('a').attr('href');     $('html, body').animate({         scrolltop: $(next).offset().top     }, 500); })  $('.previous').click(function (e) {     var prev = $('.navbar ul li.active').prev().find('a').attr('href');     $('html, body').animate({         scrolltop: $(prev).offset().top     }, 500); }) 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -