【问题标题】:SVG animation in wordpress - fillwordpress 中的 SVG 动画 - 填充
【发布时间】:2015-07-30 05:44:42
【问题描述】:

我有一个简单的动画,它可以在普通的 HTML 网站上运行,但当我将代码复制到 wordpress 帖子时却不行。

我已经创建了一个子主题,复制了样式,复制了 js。它不起作用。我之前检查过 - jquery 脚本有效。我添加了一个插件“添加完整的 SVG 支持”。 Wordpress 显示 SVG,但不知何故没有设置样式。

我的 HTML

<div class="icon-box">
<h3 class="text-box">TESTING</h3>
<a href="some link">
<img id="imgswap" class="img-btn svg" src="link to file/checkmark2.svg">
</a>

我的 CSS

svg {
    width: 75px; 
    height: auto;
    display: block;
    margin-left: auto;
    margin-right: auto;
    fill: #016fa0;
}

svg:hover {
    fill: #6c91a2;
}

我的 JS

var $j = jQuery.noConflict();

    $j('img.svg').each(function(){
        var $img = $j(this);
        var imgID = $img.attr('id');
        var imgClass = $img.attr('class');
        var imgURL = $img.attr('src');

        $j.get(imgURL, function(data) {
            // Get the SVG tag, ignore the rest
            var $svg = $j(data).find('svg');

            // Add replaced image's ID to the new SVG
            if(typeof imgID !== 'undefined') {
                $svg = $svg.attr('id', imgID);
            }
            // Add replaced image's classes to the new SVG
            if(typeof imgClass !== 'undefined') {
                $svg = $svg.attr('class', imgClass+' replaced-svg');
            }

            // Remove any invalid XML tags as per http://validator.w3.org
            $svg = $svg.removeAttr('xmlns:a');

            // Replace image with new SVG
            $img.replaceWith($svg);

        }, 'xml');

    });

【问题讨论】:

  • 我想您运行 wordpress 安装的域与您的 html 站点不同? link to file/checkmark2.svg 与您的 wp 安装在不同的服务器上吗?

标签: javascript jquery css wordpress svg


【解决方案1】:

在您的 CSS 中,您需要指定它是一个类,因为 svg 不是一种 html 标签 -

.svg {
    width: 75px; 
    height: auto;
    display: block;
    margin-left: auto;
    margin-right: auto;
    fill: #016fa0;
}

.svg:hover {
    fill: #6c91a2;
}

【讨论】:

    猜你喜欢
    • 2017-08-30
    • 2020-03-14
    • 1970-01-01
    • 2019-11-10
    • 2018-05-20
    • 2018-07-30
    • 2017-08-14
    • 2015-12-07
    • 2021-07-01
    相关资源
    最近更新 更多