Leon
Leon

Reputation: 33

JQuery slideTo after slideToogle has completed

i have this jquery code which successfully uses slideToggle to open and close a div below.

$('#map-wrap').slideUp("fast");
$('#get-here-btn').click(function() {
    if (!$("#map-wrap").is(":visible"))
    $('#get-here-btn').addClass("active").html('Close');

    $("#map-wrap").slideToggle("fast","linear",function() { 
    if (!$("#map-wrap").is(":visible"))
        $('#get-here-btn').removeClass("active").html('How to get here');
       });       
});

i'd like to scrollTo the now-open div once it's open (with some sort of easing). i've tried a few variations and i can only get it to jump to the location (is this because the element is hidden when the button is clicked?) rather than slide.

i know i should probably add the scrollTo into the slideToggle function but am not sure where?

any help much appreciated. thanks in advance, Leon

i've knocked up a JSFiddle: http://jsfiddle.net/leonharris/rZqwx

Upvotes: 1

Views: 760

Answers (1)

Kiruse
Kiruse

Reputation: 1743

Taken from this question:

Assuming you have a button with the id 'button', try this example:

$("#button").click(function() {
    $('html, body').animate({
        scrollTop: $("#elementtoScrollToID").offset().top
    }, 2000);
});

Obviously you'd have to adapt it to your case.

Upvotes: 1

Related Questions