Scrolling to an Anchor using Transition/CSS3

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

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


      
10条回答
  •  感动是毒
    2020-11-30 20:45

    You can find the answer to your question on the following page:

    https://stackoverflow.com/a/17633941/2359161

    Here is the JSFiddle that was given:

    http://jsfiddle.net/YYPKM/3/

    Note the scrolling section at the end of the CSS, specifically:

    /*
     *Styling
     */
    
    html,body {
        width: 100%;
        height: 100%;
        position: relative; 
    }
    body {
    overflow: hidden;
    }
    
    header {
    background: #fff; 
    position: fixed; 
    left: 0; top: 0; 
    width:100%;
    height: 3.5rem;
    z-index: 10; 
    }
    
    nav {
    width: 100%;
    padding-top: 0.5rem;
    }
    
    nav ul {
    list-style: none;
    width: inherit; 
    margin: 0; 
    }
    
    
    ul li:nth-child( 3n + 1), #main .panel:nth-child( 3n + 1) {
    background: rgb( 0, 180, 255 );
    }
    
    ul li:nth-child( 3n + 2), #main .panel:nth-child( 3n + 2) {
    background: rgb( 255, 65, 180 );
    }
    
    ul li:nth-child( 3n + 3), #main .panel:nth-child( 3n + 3) {
    background: rgb( 0, 255, 180 );
    }
    
    ul li {
    display: inline-block; 
    margin: 0 8px;
    margin: 0 0.5rem;
    padding: 5px 8px;
    padding: 0.3rem 0.5rem;
    border-radius: 2px; 
    line-height: 1.5;
    }
    
    ul li a {
    color: #fff;
    text-decoration: none;
    }
    
    .panel {
    width: 100%;
    height: 500px;
    z-index:0; 
    -webkit-transform: translateZ( 0 );
    transform: translateZ( 0 );
    -webkit-transition: -webkit-transform 0.6s ease-in-out;
    transition: transform 0.6s ease-in-out;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    
    }
    
    .panel h1 {
    font-family: sans-serif;
    font-size: 64px;
    font-size: 4rem;
    color: #fff;
    position:relative;
    line-height: 200px;
    top: 33%;
    text-align: center;
    margin: 0;
    }
    
    /*
     *Scrolling
     */
    
    a[ id= "servicios" ]:target ~ #main article.panel {
    -webkit-transform: translateY( 0px);
    transform: translateY( 0px );
    }
    
    a[ id= "galeria" ]:target ~ #main article.panel {
    -webkit-transform: translateY( -500px );
    transform: translateY( -500px );
    }
    a[ id= "contacto" ]:target ~ #main article.panel {
    -webkit-transform: translateY( -1000px );
    transform: translateY( -1000px );
    }
    
    
    
    
    
    

    Nuestros Servicios

    Mustra de nuestro trabajos

    Pongamonos en contacto

提交回复
热议问题