Nescio
Nescio

Reputation: 28443

How to scroll to an element after expanding with slideToggle?

scrollTo is not scrolling to a div that expands past the bottom of the page... any suggestions? (jQuery 1.3, scrollTo 1.42)

function toggleCollapsible(ownerDiv) {
    ownerDiv.next(".Collapsible").slideToggle("fast", 
                                              $.scrollTo(ownerDiv, "slow"));
}

Upvotes: 1

Views: 2476

Answers (1)

Juraj Blahunka
Juraj Blahunka

Reputation: 18543

Tried your code and it works, but you forgot to specify, that $.scrollTo should be inside an anonymous function (callback after slideToggle finishes toggling) and it even scrolled to under bottom of page..

function toggleCollapsible(ownerDiv) {
    ownerDiv.next(".Collapsible").slideToggle("fast", function(){
        $.scrollTo(ownerDiv, "slow");
    });
}
toggleCollapsible($("#target"));

Upvotes: 1

Related Questions