Mom Mom - 5 months ago 121
jQuery Question

How to make Auto scroll page in Jquery and bootstrap

I want to use this scroll nav in this link
http://startbootstrap.com/template-overviews/scrolling-nav/

for scrolling pages it is needed to click the link but I want this issue is done automatically without need to click.

could anyone help me to change this code for doing this issue ?

//jQuery for page scrolling feature - requires jQuery Easing plugin
$(function() {
$('a.page-scroll').bind('click', function(event) {
var $anchor = $(this);
$('html, body').stop().animate({
scrollTop: $($anchor.attr('href')).offset().top
}, 1500, 'easeInOutExpo');
event.preventDefault();
});
})

Answer

Just move the animate function out of the event listener(but inside the jQuery's document ready function) and it will be executed without the need of a click.

$(function() {
    $('html, body').stop().animate({
        scrollTop: $($('a.page-scroll').eq(2).attr('href')).offset().top
    }, 1500, 'easeInOutExpo');
});

You can try it directly in the link of your post, in the console.

Note: I added the .eq(2) to get the second button's href of the link in your post.