CSS3 translate out of screen

后端 未结 8 1692
南旧
南旧 2021-02-07 07:48

For a number of projects now I have had elements on the page which I want to translate out of the screen area (have them fly out of the document). In proper code this should be

8条回答
  •  青春惊慌失措
    2021-02-07 08:08

    What I did is use the vh (view height) unit. It's always relative to the screen size, not the element itself:

    /* moves the element one screen height down */
    translateY(calc(100vh))
    

    So if you know the position of the element in the screen (say top:320px), you can move it exactly off the screen:

    /* moves the element down exactly off the bottom of the screen */
    translateY(calc(100vh - 320px))
    

提交回复
热议问题