scrollTop jquery, scrolling to div with id?

前端 未结 5 2030
面向向阳花
面向向阳花 2020-12-24 07:08

So this is the current code I have

$(document).ready(function() {
    $(\'.abouta\').click(function(){
        $(\'html, body\').animate({scrollTop:308}, \'s         


        
相关标签:
5条回答
  • 2020-12-24 07:29

    instead of

    $('html, body').animate({scrollTop:xxx}, 'slow');
    

    use

    $('html, body').animate({scrollTop:$('#div_id').position().top}, 'slow');
    

    this will return the absolute top position of whatever element you select as #div_id

    0 讨论(0)
  • 2020-12-24 07:37

    try this

        $('#div_id').animate({scrollTop:0}, '500', 'swing');
    
    0 讨论(0)
  • 2020-12-24 07:49

    My solution was the following:

    document.getElementById("agent_details").scrollIntoView();
    
    0 讨论(0)
  • 2020-12-24 07:51

    try this:

    $('html, body').animate({scrollTop:$('#xxx').position().top}, 'slow');
    $('#xxx').focus();
    
    0 讨论(0)
  • 2020-12-24 07:52

    if you want to scroll just only some div, can use the div id instead of 'html, body'

    $('html, body').animate(...
    

    use

    $('#mydivid').animate(...
    
    0 讨论(0)
提交回复
热议问题