如何选择使用Snap.svg现有的SVG片段 [英] How to select fragments of an existing SVG using Snap.svg

查看:171
本文介绍了如何选择使用Snap.svg现有的SVG片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在本地运行 Snap.svg ,但Snap.load()函数,使一个AJAX请求,这是不允许在本地(在Chrome,反正)。下面是我的code:

I'm trying to run Snap.svg locally, but the Snap.load() function makes an AJAX request, which isn't allowed locally (in Chrome, anyways). Below is my code:

window.onload = function () {

    var s = Snap("#headDiv");
    Snap.load("emotions.svg", function(f) {

        eyes = f.select("#eyes");
        lids = f.select("#lids");
        head = f.select("#head");

        s.append(f);
    });
};

所以,虽然这工作得很好,从一台服务器,我想获得这个在本地运行。什么是我最好的选择,包括我的 emotions.svg 文件而不做一个AJAX请求?

So while this works fine from a server, I'd like to get this to run locally. What would be my best option to include my emotions.svg file without making an AJAX request?

我知道它很容易只是扔SVG的DIV,但我不能够访问片段,与我目前的脚本的方式。任何想法?

I know it's easy to just throw the SVG in the DIV, but I wasn't able to access the fragments that way with my current script. Any ideas?

推荐答案

更​​改:

window.onload = function () {

var s = Snap("#headDiv");
Snap.load("emotions.svg", function(f) {

    eyes = f.select("#eyes");
    lids = f.select("#lids");
    head = f.select("#head");

    s.append(f);
});
};

要简单的:

window.onload = function () {

    eyes = Snap.select("#eyes");
    lids = Snap.select("#lids");
    head = Snap.select("#head");
};

,然后把实际的SVG脚本中的目标DIV伟大的工作。

And then placing the actual SVG script in the target DIV worked great.

这篇关于如何选择使用Snap.svg现有的SVG片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆