svg下css定位和添加css3动画之后定位失效问题 解决小红包酬谢

html-css09

svg下css定位和添加css3动画之后定位失效问题 解决小红包酬谢,第1张

搜了几篇老外的文章,提到 svg 的 forginObject 内的 HTML 元素,当应用 CSS3 动画时,动画的 transform-origin 是基于最外层 body 定位的,貌似无解。

个人建议使用 svg 的 SMIL 动画来实现波纹特效,你大屏展示用的话,兼容性啥的应该不是主要问题。写了简单示例代码:

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

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

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

    <title>svg 动画示例</title>

    <style>

    html,

    body,

    svg {

        width: 100%

        height: 100%

    }

    body {

        padding: 0

        margin: 0

        background: #232323

    }

    .eanimation {

        stroke: rgb(181, 255, 255)

        box-shadow: inset 0px 0px 8px rgba(29, 146, 226, 0.75)

    }

    </style>

</head>

<body>

    <svg xmlns="http://www.w3.org/2000/svg">

        <g>

            <g>

                <circle class="eanimation" cx="200" cy="200" r="96" stroke-width="3" fill="transparent"/>

                <animateTransform

                 attributeName="transform"

                 type="scale"

                 dur="1s"

                 values="0.51"

                 repeatCount="indefinite"/>

            </g>

            <g>

                <circle class="eanimation" cx="200" cy="200" r="96" stroke-width="3" fill="transparent"/>

                <animateTransform

                    attributeName="transform"

                    type="scale"

                    dur="1s"

                    values="0.651"

                    additive="sum"

                    repeatCount="indefinite"/>

            </g>

            <animate attributeName="opacity" begin="0s" dur="1s" from="1" to="0" repeatCount="indefinite"/>

        </g>

    </svg>

</body>

</html>

animation 属性是一个简写属性,用于设置六个动画属性:

如需修改在页面中的位置

将 .point 设为 position:absoulute ,修改其 left , top 位置即可

.point-flicker 是相对 .point 来定位的

修改大小时要将它的 margin-left: -40px margin-top: -40px改为对应大小的一半