Show div on click and scroll to it

前端 未结 2 1578
星月不相逢
星月不相逢 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);
    });
    

提交回复
热议问题