Scrolling to an Anchor using Transition/CSS3

前端 未结 10 902
-上瘾入骨i
-上瘾入骨i 2020-11-30 20:07

I have a series of links which are using an anchor mechanism:


      
10条回答
  •  鱼传尺愫
    2020-11-30 20:51

    Here is a pure css solution using viewport units and variables that automatically scales to the device (and works on window resize). I added the following to Alex's solution:

            html,body {
                width: 100%;
                height: 100%;
                position: fixed;/* prevents scrolling */
                --innerheight: 100vh;/* variable 100% of viewport height */
            }
    
            body {
                overflow: hidden; /* prevents scrolling */
            }
    
            .panel {
                width: 100%;
                height: var(--innerheight); /* viewport height */
    
            a[ id= "galeria" ]:target ~ #main article.panel {
                -webkit-transform: translateY( calc(-1*var(--innerheight)) );
                transform: translateY( calc(-1*var(--innerheight)) );
            }
    
            a[ id= "contacto" ]:target ~ #main article.panel {
                -webkit-transform: translateY( calc(-2*var(--innerheight)) );
                transform: translateY( calc(-2*var(--innerheight)) );
    

提交回复
热议问题