Show div on click and scroll to it

前端 未结 2 1579
星月不相逢
星月不相逢 2021-01-15 23:27

I have a javascript function to show/hide a div on click and I would like the page to scroll down to that div on show function. I have included the ScrollTop function but it

相关标签:
2条回答
  • 2021-01-16 00:12
    $('#output').hide();
    
    $('#readMore').click(function(){
    $('#output').show(150);
    $('#readMore').hide(150);
    $('html, body').scrollTop($('#output').offset().top);
     return false;//return  need to be placed here
    });
    
    $('#readLess').click(function(){
    $('#output').hide(150);
    $('#readMore').show(150);
    });
    
    0 讨论(0)
  • 2021-01-16 00:23

    Please put the return false; at the end.

    $('#readMore').click(function(){
        $('#output').show(150);
        $('#readMore').hide(150);
        $('html, body').scrollTop($('#output').offset().top);
        return false; // Please put the return false; at the end.
    });
    
    0 讨论(0)
提交回复
热议问题