Minirock Minirock - 3 years ago 119
jQuery Question

Scroll to div from li

I have a symfony view which looks like this

{% for menu in menus %}

I want to be able to go on a specific div when I click to the li element.

Here is the full simplified page:

{% for menu in menus %}
{% endfor %}
<p id="generalAnchor">Some text</p>
//And here i include some view depending on the li element clicked.

But in fact, when depending on the imported view size, the page is not really pretty.

So I want to scroll directly to the generalAnchor element.
I know I can do this with
but here I need to work with the
and I don't know what method I can use.

Answer Source

you can use jquery to scroll to the div.

 $("li").click(function() {
    $('html, body').animate({
        scrollTop: $("#generalAnchor").offset().top
    }, 2000);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download