How to position horizontal scroll bar at center of DIV

前端 未结 6 822
温柔的废话
温柔的废话 2020-12-18 01:51

I was trying to position horizontal scroll bar at the center of that div. I tired with window.scrollTo() but this works for page scroll and not for div scroll.



        
6条回答
  •  不知归路
    2020-12-18 02:39

    You can simplay achive this by,

    $(document).ready(()=>{
        $('#scroll').scrollIntoView({ inline: 'center' });
    });
    

    OR

    $(document).ready(()=> {
        let outerContent = $('.abc');
        let innerContent = $('.abc > div');
        outerContent.scrollLeft((innerContent.width() - outerContent.width()) / 2);        
    });
    

提交回复
热议问题