JQuery scrollTop only works once

I use this bit of code to open a div and scroll to it. It works well, but only the first time I use it, even when refreshing the page it will not work again. Does anyone know why this is happening? Thanks in advance!

Here is the URL ( www.patrickorr.ca )

$(document).ready(function() {
$("div.ftropen")
    .click(function(){
        $("div#connect").animate({height: "500px" }, "fast");                                              
        $("div#ftrconnect").fadeOut("fast");  //hide connectbtn
        $("div#ftrhide").fadeIn("fast");  //show hidebtn
        $("#connect").scrollTop($("#connect").scrollTop() + 500);
    return false;
});
$("div.ftrclose")
    .click(function(){
        $("div#connect").animate({height: "0px" }, "fast");                                            
        $("div#ftrhide").fadeOut("fast");  //hide hidebtn
        $("div#ftrconnect").fadeIn("fast");  //show connectbtn
    return false;
});
});
+5
source share
2 answers

There seems to be a problem with the library jquery.anchor.jsthat gives me Uncaught TypeError: Cannot read property 'top' of null jquery.anchor.js:32in Chrome 14. I commented on this and replaced the public function:

$("div.ftropen").click(function(){
    $("div#connect").animate({height: "500px" }, "fast", function() {
        $("body").scrollTop( $("#connect").position().top);
    });                                    
    $("div#ftrconnect").fadeOut("fast");  //hide connectbtn
    $("div#ftrhide").fadeIn("fast");  //show hidebtn
    return false;
});

which scrolls the body to the top <div id="connect">

I will see if I can create the animate animate and hellip plugin;

Anchor Slider, -, <div> click. <a> . , Anchor Slider "" jQuery animate() .

: jquery.anchor.js script,

<div id="connect" style="height:0px; display:block;"><a style="display:block;margin-top:500px;height:100px;" id="target" name="target">f</a></div>

JavaScript:

$(document).ready(function() {
    $('div.ftropen').click(function(event){
        $('div#connect').animate({height: '500px' }, 'fast', function() {
            $('body').animate({scrollTop : $('#target').position().top + 500}, 700);
        });
        $('div#ftrconnect').fadeOut('fast');  //hide connectbtn
        $('div#ftrhide').fadeIn('fast');  //show hidebtn
        event.stopPropagation();
        return false;
    });
    $('div.ftrclose')
        .click(function(){
            $('div#connect').animate({height: '0px' }, 'fast');
            $('div#ftrhide').fadeOut('fast');  //hide hidebtn
            $('div#ftrconnect').fadeIn('fast');  //show connectbtn
        return false;
    });
});

<a id="target">, <div> .

Edit2: ​​.

+1

    $("body").animate({

    $("html:not(:animated),body:not(:animated)").animate({

BODY HTML - Mozilla Webkit. . : not (: ) . JS , , - ...

    $('#DIV a[href^=#]').click(function(e) {
       e.preventDefault();
       var h = $(this).attr('href');
       $("html:not(:animated),body:not(:animated)").animate({ scrollTop: $(h).offset().top }, 1200);
    });
0

All Articles