Search code examples
jqueryscrollfadein

Nasty jump to fadein div


I am making a portfolio. If people click on "Show work" it makes the div "portfolio" visible trough the following jquery code:

function() {
    $("#more").click(function() {
        $("#portfolio").fadeIn("slow");
    });

It works perfectly, but the problem is, its down the page and it jumps to it.

My question is, is it possible to let it scroll downwards instead of jump?


Solution

  • Add a preventDefault() in there to stop the a functioning as an anchor tag:

    $("#more").click(function(e) {
        e.preventDefault();
        $("#portfolio").fadeIn("slow");
    });
    

    Depending on which jQuery version you're using you may also want to change that .click() to .on('click'...), too.