formular to calculate width/height (relative to parent) of container with translateZ inside of parent container with perspective

前端 未结 3 655
借酒劲吻你
借酒劲吻你 2020-12-16 16:00

What is the formular to calculate the widths/heights of child elements with translateZ inside of parent container with set perspective (keyword: &

3条回答
  •  鱼传尺愫
    2020-12-16 16:42

    The formular to calculate the widths/heights of child elements with translateZ inside of parent container with set perspective is:
    $scale = 1 + (translateZ * -1) / perspective.


    Where to throw this formular at transform: scale( $scale ).
    perspective is parents perspective value and translateZ is elements translateZ value as well. See snippet at the bottom or SASS mockup as you like.


    So actually the answer was given in the question!
    While this is the correct answer to the asked question this didn't solve my specific problem at all so here is a follow-up-question.


    Credits: @Trolleymusic who at least opened my eyes somehow with his answer.


    CSS example:

    /* formular: 1 + (translateZ * -1) / perspective */
    
    #parent {
      perspective: 10px;
    }
    
    .child--1 { /* 1 + (-100 * -1) / 10 */
      transform: translateZ(-100px) scale( 11 );
    }
    
    .child--2 { /* 1 + (-200 * -1) / 10 */
      transform: translateZ(-200px) scale( 21 );
    }
    
    .child--3 { /* 1 + (1 * -1) / 10 */
      transform: translateZ(1px) scale( 0.9 );
    }
    

提交回复
热议问题