css3 图片平移出现

html-css029

css3 图片平移出现,第1张

 <!DOCTYPE html>

<html lang="en">

    <head>

        <meta charset="UTF-8" />

        <meta http-equiv="X-UA-Compatible" content="IE=edge" />

        <meta name="viewport" content="width=device-width, initial-scale=1.0" />

        <title>Document</title>

        <style>

            * {

                margin: 0

                padding: 0

            }

            div {

                background: red

                width: 200px

                height: 200px

                position: relative

                transform: translateX(-200px)

                animation-name: mymove

                animation-duration: 2s

                animation-fill-mode: forwards

            }

            @keyframes mymove {

                from {

                    transform: translateX(-200px)

                }

                to {

                    transform: translateX(0px)

                }

            }

        </style>

    </head>

    <body>

        <div></div>

    </body>

</html>

 请采纳

如果你想只向一移的话,你需要修改translate

-webkit-transform:translateY(100px)

-moz-transform:translateY(100px)

这样才是向下移动100px,

因为translate

默认是移动XY轴的,意思就是说,移动左右以及上下一起,但是默认平移而已,

如果你想单独操作Y的话,就要translateY,单独操作X用translateX,当然默认translate

(100px)相当于translateX(100px)

如果你想向右移的同时又向下移

-webkit-transform:translate(100px,100px)

-moz-transform:translate(100px,100px)

这样你应该能理解translate的用法 了。。。