所以我得到了使用SVG围绕此圆旋转的文本。我想用图像填充它,以使其平淡无奇。这是我的HTML中的代码。

    <div id="container">
        <div id="circle">
            <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="300px"
                height="300px" viewBox="0 0 300 300" enable-background="new 0 0 300 300" xml:space="preserve">
                <defs>
                    <pattern id='my_portrait'>
                        <image xlink:href="http://gastv.mx/wp-content/uploads/2014/05/jumex.jpg" x="-30" y="-30"
                        width="380" height="267" />
                    </pattern>
                    <path id="circlePath" d=" M 150, 150 m -60, 0 a 60,60 0 0,1 120,0 a 60,60 0 0,1 -120,0 " />
                </defs>
                <circle cx="150" cy="100" r="75" fill="none"/>
                <g id="rotating_text">
                    <use xlink:href="#circlePath" fill="rgb(81,84,77)"  stroke="black" stroke-width="2px"/>
                    <text fill="#000">
                        <textPath xlink:href="#circlePath" fill="white">Curse this circular mass of misery!!!</textPath>
                    </text>
                </g>
            </svg>
        </div>
    </div>


这就是CSS定义的速度和浏览器支持。

    #circle svg {
width: 100%;
-webkit-animation-name: rotate;
-moz-animation-name: rotate;
-ms-animation-name: rotate;
-o-animation-name: rotate;
animation-name: rotate;
-webkit-animation-duration: 20s;
-moz-animation-duration: 20s;
-ms-animation-duration: 20s;
-o-animation-duration: 20s;
animation-duration: 20s;
-webkit-animation-iteration-count: infinite;
-moz-animation-iteration-count: infinite;
-ms-animation-iteration-count: infinite;
-o-animation-iteration-count: infinite;
animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-moz-animation-timing-function: linear;
-ms-animation-timing-function: linear;
-o-animation-timing-function: linear;
animation-timing-function: linear;
}

@-webkit-keyframes rotate {
    from {
        -webkit-transform: rotate(360deg);
    }
    to {
        -webkit-transform: rotate(0);
    }
}

@-moz-keyframes rotate {
    from {
        -moz-transform: rotate(360deg);
    }
    to {
        -moz-transform: rotate(0);
    }
}

@-ms-keyframes rotate {
    from {
        -ms-transform: rotate(360deg);
    }
    to {
        -ms-transform: rotate(0);
    }
}

@-o-keyframes rotate {
    from {
        -o-transform: rotate(360deg);
    }
    to {
        -o-transform: rotate(0);
    }
}

@keyframes rotate {
    from {
        transform: rotate(360deg);
    }
    to {
        transform: rotate(0);
    }
}


我尝试了几种不同的方法来填补内部圆圈,但似乎没有任何改变。任何帮助将不胜感激!

最佳答案

添加patternUnits="userSpaceOnUse" height="380" width="267" in my_portrait
并在fill="url(#my_portrait)"中添加circlePath


#circle svg {
width: 100%;
-webkit-animation-name: rotate;
-moz-animation-name: rotate;
-ms-animation-name: rotate;
-o-animation-name: rotate;
animation-name: rotate;
-webkit-animation-duration: 20s;
-moz-animation-duration: 20s;
-ms-animation-duration: 20s;
-o-animation-duration: 20s;
animation-duration: 20s;
-webkit-animation-iteration-count: infinite;
-moz-animation-iteration-count: infinite;
-ms-animation-iteration-count: infinite;
-o-animation-iteration-count: infinite;
animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-moz-animation-timing-function: linear;
-ms-animation-timing-function: linear;
-o-animation-timing-function: linear;
animation-timing-function: linear;
}

@-webkit-keyframes rotate {
    from {
        -webkit-transform: rotate(360deg);
    }
    to {
        -webkit-transform: rotate(0);
    }
}

@-moz-keyframes rotate {
    from {
        -moz-transform: rotate(360deg);
    }
    to {
        -moz-transform: rotate(0);
    }
}

@-ms-keyframes rotate {
    from {
        -ms-transform: rotate(360deg);
    }
    to {
        -ms-transform: rotate(0);
    }
}

@-o-keyframes rotate {
    from {
        -o-transform: rotate(360deg);
    }
    to {
        -o-transform: rotate(0);
    }
}

@keyframes rotate {
    from {
        transform: rotate(360deg);
    }
    to {
        transform: rotate(0);
    }
}

<div id="container">
        <div id="circle">
            <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="300px"
                height="300px" viewBox="0 0 300 300" enable-background="new 0 0 300 300" xml:space="preserve">
                <defs>
                    <pattern id='my_portrait' patternUnits="userSpaceOnUse" height="380" width="267">
                        <image xlink:href="http://gastv.mx/wp-content/uploads/2014/05/jumex.jpg" x="-30" y="-30"
                        width="380" height="267"  />
                    </pattern>
                    <path id="circlePath" d=" M 150, 150 m -60, 0 a 60,60 0 0,1 120,0 a 60,60 0 0,1 -120,0 " fill="url(#my_portrait)" />
                </defs>
                <circle cx="150" cy="100" r="75" fill="none"/>
                <g id="rotating_text">
                    <use xlink:href="#circlePath" fill="rgb(81,84,77)"  stroke="black" stroke-width="2px"/>
                    <text fill="#000">
                        <textPath xlink:href="#circlePath" fill="white">Curse this circular mass of misery!!!</textPath>
                    </text>
                </g>
            </svg>
        </div>
    </div>

关于html - 用图案图像填充旋转的圆形SVG,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50283115/

10-13 03:51