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

html-css011

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>

特殊字体一般不是说不能添加,而是考虑到用户电脑上预装的字体有限,所以局限在宋体和微软雅黑两种字体,css属性中有个font属性,例如{font-family:"迷你简菱心"},在装过这个字体的的电脑会有效果,但是再没有装过的电脑可能就是其它字体了,一般会解析为宋体,问题解决一般由两种解决方案。

第一:css3下载字体,代码如下

@font-face

{

font-family:

'自己命名字体名字'

src:

url('字体路径')

src:

url('FileName.eot?#iefix')

format('embedded-opentype'),

/*其它格式*/

url('FileName.woff')

format('woff'),

url('FileName.ttf')

format('truetype'),

url('FileName.svg#FontName')

format('svg')

font-style:

normal

font-weight:

normal

/*设置默认样式*/

}

.aa{font-family:"自己命名字体名字"}

不兼容ie8及以下浏览器

第二:切png图片

关于CSS的特效,大部分都是使用了hover事件,或者你再完成一些特殊要求的时候,你会使用mouseenter和mouseleave来代替hover,我就遇到过一种就是鼠标移开时,悬浮显示的元素依然占了文档流,而且你不能使用display:none来隐藏他,这样的话,过渡效果会受到影响!

最简单的hover写法,淡入淡出,关键在于pointer-events的使用,保证淡入淡出都有过渡效果的同时,子元素不会被父元素hover事件所影响!