-2

How to do scroll page after click button in jquery. In menu (li) after scroll to div i want add class "active". How to do this and how scroll to element after click. All in jquery.
This is what i try to do

    function scrollToPosition('#menu') {
    if ("#menu" !== undefined) {
        $("li.m_top").addClass('active')
        $("li.m_top").removeClass('active')
        $("#menu").scrollTo()
    });

}}
<div id="menu">
        <ul class="menu_top">
            <a href="#home">
            <li class="m_top">
                home
            </li></a>
            <a href="#about">
            <li class="m_top">
                about
            </li></a>
            <a href="#galery">
            <li class="m_top">
                galery
            </li></a>
            <a href="#xxx">
            <li class="m_top">
                xxx
            </li></a>
            <a href="#contact">
            <li class="m_top">
                contact
            </li></a>
        </ul>
    </div>
    <div class="clear"></div>
    <div id='home'>

    </div>
    <div id='about'>

    </div>
    <div id='galery'>

    </div>
    <div id='xxx'>

    </div>
    <div id='contact'>

    </div>
aliendev
  • 23
  • 8
  • We're not here to write all your code, however we can help you get your existing code in order. If you have some jquery that's not working then post it so we can help. Please be aware that what you want to do is easily searchable. – The Muffin Man Nov 02 '14 at 17:28

1 Answers1

0

you can use this jquery code to perform your desired action

$("li").click(function(){
 $("li").removeClass("active");
 $(this).addClass("active");
 $("body").animate({ scrollTop: $("#"+$(this).text().trim()).offset().top },3000);




});

see the js fiddle example i have created for you

jsFiddle

A.B
  • 20,110
  • 3
  • 37
  • 71