javascript - 如何让 Grunticon 'data-grunticon-embed' 选项嵌入工作

标签 javascript css svg

我在使用来自 grunticon 的 data-grunticon-embed 时遇到问题。 https://github.com/filamentgroup/grunticon

我已经尝试在本地和我的网络服务器上运行它,但在 Chrome 或 Safari 中似乎没有任何结果。

我的 Gruntfile.js

module.exports = function(grunt) {
    // Project configuration.
    grunt.initConfig({
        grunticon: {
            myIcons: {
                    files: [{
                        expand: true,
                        cwd: 'grunt/svgs',
                        src: ['*.svg', '*.png'],
                        dest: "grunt/output"
                    }],
                options: {
                    loadersnippet: "grunticon.loader.js",
                    enhanceSVG: true,
                }
            }
        }
    });
    grunt.loadNpmTasks('grunt-grunticon');
    grunt.registerTask('default', ['grunticon:myIcons']);
};

在我的标题中我有

<script>
/* grunticon Stylesheet Loader | https://github.com/filamentgroup/grunticon | (c) 2012 Scott Jehl, Filament Group, Inc. | MIT license. */
        window.grunticon=function(e){if(e&&3===e.length){var t=window,n=!(!t.document.createElementNS||!t.document.createElementNS("http://www.w3.org/2000/svg","svg").createSVGRect||!document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Image","1.1")||window.opera&&-1===navigator.userAgent.indexOf("Chrome")),o=function(o){var r=t.document.createElement("link"),a=t.document.getElementsByTagName("script")[0];r.rel="stylesheet",r.href=e[o&&n?0:o?1:2],a.parentNode.insertBefore(r,a)},r=new t.Image;r.onerror=function(){o(!1)},r.onload=function(){o(1===r.width&&1===r.height)},r.src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw=="}};
        grunticon(["<?php echo get_template_directory_uri(); ?>/grunt/output/icons.data.svg.css", "<?php echo get_template_directory_uri(); ?>/grunt/output/icons.data.png.css", "<?php echo get_template_directory_uri(); ?>/grunt/output/icons.fallback.css"], grunticon.svgLoadedCallback );
        </script>
<noscript><link href="<?php echo get_template_directory_uri(); ?>/grunt/output/icons.fallback.css" rel="stylesheet"></noscript>

在我的页面上,我正在使用它,图标看起来很好,但没有嵌入 svg 数据。

<div class="icon-twitter" style="width: 50px; height: 50px; background-size:50%;" data-grunticon-embed></div></a>


更新:

对此仍然不满意。我现在在我的服务器上运行它 http://benjgorman.com/页脚/导航中的图标是 svg。我可以看出浏览器正在获取 SVG 数据,正如我在控制台中看到的那样,但它不是内嵌在页面上的,因此它无法设置样式。

Console information

Inspect element on same icon

最佳答案

事实证明,当我遵循过时的教程时,我使用了错误版本的 Grunticon。我的 package.json 现在看起来像下面需要修改的内容。之后一切正常。

{
    "name": "my-grunticon-test",
    "version": "0.1.0",
    "dependencies": {
        "grunt": "~0.4.4",
        "grunt-grunticon": "~2.2.1"

    }
}

关于javascript - 如何让 Grunticon 'data-grunticon-embed' 选项嵌入工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31842494/

相关文章:

javascript - 将 JavaScript 对象值复制到 javascript 中的关联数组中

javascript - 我无法通过悬停或鼠标输入来取消绑定(bind)并再次重新绑定(bind)

javascript - jquery向下滚动时如何获取浏览器屏幕窗口的位置

css - Bootstrap 导航栏下拉按钮

html - 主动在 bootstrap 4 选项卡中不工作

javascript - 内联 SVG 动画最佳实践

HTML 按钮元素 - 内部的 svg 图像 - 奇怪的间隙和定位

javascript - 在 JavaScript 中创建键/值对列表

javascript - 我可以在桌面以外的所有内容上隐藏 html5 视频标签吗?

debugging - 有没有在线工具可以测试 SVG 路径?