Is it possible to use Snap inside an SVG?
I am following the tutorial at https://css-tricks.com/video-screencasts/135-three-ways-animate-svg/ and I'm trying to put everything inside an svg but the js part uses Snap and doesn't work.
I tried
<svg version="1.1" id="robot" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 127.9 178.4" enable-background="new 0 0 127.9 178.4" xml:space="preserve">
<script src="https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.5.1/snap.svg-min.js">
var s = Snap("#robot");
var leftPupil = s.select("#left-pupil");
leftPupil.attr({
fill: "green"
});
leftPupil.animate({
r: 50,
fill: "lightgreen"
}, 1000);
</script>
</svg>
but the console says Snap is not defined. Is it possible to load it in some way just using SVG?
javascript svg snap.svg
add a comment |
I am following the tutorial at https://css-tricks.com/video-screencasts/135-three-ways-animate-svg/ and I'm trying to put everything inside an svg but the js part uses Snap and doesn't work.
I tried
<svg version="1.1" id="robot" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 127.9 178.4" enable-background="new 0 0 127.9 178.4" xml:space="preserve">
<script src="https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.5.1/snap.svg-min.js">
var s = Snap("#robot");
var leftPupil = s.select("#left-pupil");
leftPupil.attr({
fill: "green"
});
leftPupil.animate({
r: 50,
fill: "lightgreen"
}, 1000);
</script>
</svg>
but the console says Snap is not defined. Is it possible to load it in some way just using SVG?
javascript svg snap.svg
<script src="some url"></script> <script> some code
– Felipe Valdes
Jan 1 at 3:47
add a comment |
I am following the tutorial at https://css-tricks.com/video-screencasts/135-three-ways-animate-svg/ and I'm trying to put everything inside an svg but the js part uses Snap and doesn't work.
I tried
<svg version="1.1" id="robot" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 127.9 178.4" enable-background="new 0 0 127.9 178.4" xml:space="preserve">
<script src="https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.5.1/snap.svg-min.js">
var s = Snap("#robot");
var leftPupil = s.select("#left-pupil");
leftPupil.attr({
fill: "green"
});
leftPupil.animate({
r: 50,
fill: "lightgreen"
}, 1000);
</script>
</svg>
but the console says Snap is not defined. Is it possible to load it in some way just using SVG?
javascript svg snap.svg
I am following the tutorial at https://css-tricks.com/video-screencasts/135-three-ways-animate-svg/ and I'm trying to put everything inside an svg but the js part uses Snap and doesn't work.
I tried
<svg version="1.1" id="robot" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 127.9 178.4" enable-background="new 0 0 127.9 178.4" xml:space="preserve">
<script src="https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.5.1/snap.svg-min.js">
var s = Snap("#robot");
var leftPupil = s.select("#left-pupil");
leftPupil.attr({
fill: "green"
});
leftPupil.animate({
r: 50,
fill: "lightgreen"
}, 1000);
</script>
</svg>
but the console says Snap is not defined. Is it possible to load it in some way just using SVG?
<svg version="1.1" id="robot" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 127.9 178.4" enable-background="new 0 0 127.9 178.4" xml:space="preserve">
<script src="https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.5.1/snap.svg-min.js">
var s = Snap("#robot");
var leftPupil = s.select("#left-pupil");
leftPupil.attr({
fill: "green"
});
leftPupil.animate({
r: 50,
fill: "lightgreen"
}, 1000);
</script>
</svg>
<svg version="1.1" id="robot" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 127.9 178.4" enable-background="new 0 0 127.9 178.4" xml:space="preserve">
<script src="https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.5.1/snap.svg-min.js">
var s = Snap("#robot");
var leftPupil = s.select("#left-pupil");
leftPupil.attr({
fill: "green"
});
leftPupil.animate({
r: 50,
fill: "lightgreen"
}, 1000);
</script>
</svg>
javascript svg snap.svg
javascript svg snap.svg
edited Jan 1 at 15:32
ccprog
9,43521128
9,43521128
asked Dec 31 '18 at 23:28
Daniel T.Daniel T.
177
177
<script src="some url"></script> <script> some code
– Felipe Valdes
Jan 1 at 3:47
add a comment |
<script src="some url"></script> <script> some code
– Felipe Valdes
Jan 1 at 3:47
<script src="some url"></script> <script> some code
– Felipe Valdes
Jan 1 at 3:47
<script src="some url"></script> <script> some code
– Felipe Valdes
Jan 1 at 3:47
add a comment |
2 Answers
2
active
oldest
votes
A <script>
tag inside a <svg>
element is from the SVG namespace and uses the href
attribute (or xlink:href
if you adhere to SVG 1.1) instead of src
. In addition, like johnheroy said, take care to use separate elements for each script.
<svg id="robot" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ...>
<script xlink:href="https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.5.1/snap.svg-min.js" />
<!-- grafic content -->
<script>
var s = Snap("#robot");
//...
</script>
</svg>
I also tried as you suggested but still couldn't make it work. Here is the code I tried jsfiddle.net/tzuya/3dfvtq4y/1
– Daniel T.
Jan 1 at 9:43
Position the script at the end of the document. At time of parsing, the selected elemenent does not yet exist. (There still remains an error 'rgb(0, 128, 0)' is not a valid selector in the animation of the color, but I can't help you with that.)
– ccprog
Jan 1 at 15:30
add a comment |
You need to import the SnapSVG library in a separate <script>
tag from the one where you defined your own code. So try closing the first <script>
tag and then opening a new one for your code, i.e.:
<script src="https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.5.1/snap.svg-min.js"></script>
<script>
// your JS code
</script>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992120%2fis-it-possible-to-use-snap-inside-an-svg%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
A <script>
tag inside a <svg>
element is from the SVG namespace and uses the href
attribute (or xlink:href
if you adhere to SVG 1.1) instead of src
. In addition, like johnheroy said, take care to use separate elements for each script.
<svg id="robot" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ...>
<script xlink:href="https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.5.1/snap.svg-min.js" />
<!-- grafic content -->
<script>
var s = Snap("#robot");
//...
</script>
</svg>
I also tried as you suggested but still couldn't make it work. Here is the code I tried jsfiddle.net/tzuya/3dfvtq4y/1
– Daniel T.
Jan 1 at 9:43
Position the script at the end of the document. At time of parsing, the selected elemenent does not yet exist. (There still remains an error 'rgb(0, 128, 0)' is not a valid selector in the animation of the color, but I can't help you with that.)
– ccprog
Jan 1 at 15:30
add a comment |
A <script>
tag inside a <svg>
element is from the SVG namespace and uses the href
attribute (or xlink:href
if you adhere to SVG 1.1) instead of src
. In addition, like johnheroy said, take care to use separate elements for each script.
<svg id="robot" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ...>
<script xlink:href="https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.5.1/snap.svg-min.js" />
<!-- grafic content -->
<script>
var s = Snap("#robot");
//...
</script>
</svg>
I also tried as you suggested but still couldn't make it work. Here is the code I tried jsfiddle.net/tzuya/3dfvtq4y/1
– Daniel T.
Jan 1 at 9:43
Position the script at the end of the document. At time of parsing, the selected elemenent does not yet exist. (There still remains an error 'rgb(0, 128, 0)' is not a valid selector in the animation of the color, but I can't help you with that.)
– ccprog
Jan 1 at 15:30
add a comment |
A <script>
tag inside a <svg>
element is from the SVG namespace and uses the href
attribute (or xlink:href
if you adhere to SVG 1.1) instead of src
. In addition, like johnheroy said, take care to use separate elements for each script.
<svg id="robot" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ...>
<script xlink:href="https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.5.1/snap.svg-min.js" />
<!-- grafic content -->
<script>
var s = Snap("#robot");
//...
</script>
</svg>
A <script>
tag inside a <svg>
element is from the SVG namespace and uses the href
attribute (or xlink:href
if you adhere to SVG 1.1) instead of src
. In addition, like johnheroy said, take care to use separate elements for each script.
<svg id="robot" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ...>
<script xlink:href="https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.5.1/snap.svg-min.js" />
<!-- grafic content -->
<script>
var s = Snap("#robot");
//...
</script>
</svg>
edited Jan 1 at 15:37
answered Jan 1 at 1:17
ccprogccprog
9,43521128
9,43521128
I also tried as you suggested but still couldn't make it work. Here is the code I tried jsfiddle.net/tzuya/3dfvtq4y/1
– Daniel T.
Jan 1 at 9:43
Position the script at the end of the document. At time of parsing, the selected elemenent does not yet exist. (There still remains an error 'rgb(0, 128, 0)' is not a valid selector in the animation of the color, but I can't help you with that.)
– ccprog
Jan 1 at 15:30
add a comment |
I also tried as you suggested but still couldn't make it work. Here is the code I tried jsfiddle.net/tzuya/3dfvtq4y/1
– Daniel T.
Jan 1 at 9:43
Position the script at the end of the document. At time of parsing, the selected elemenent does not yet exist. (There still remains an error 'rgb(0, 128, 0)' is not a valid selector in the animation of the color, but I can't help you with that.)
– ccprog
Jan 1 at 15:30
I also tried as you suggested but still couldn't make it work. Here is the code I tried jsfiddle.net/tzuya/3dfvtq4y/1
– Daniel T.
Jan 1 at 9:43
I also tried as you suggested but still couldn't make it work. Here is the code I tried jsfiddle.net/tzuya/3dfvtq4y/1
– Daniel T.
Jan 1 at 9:43
Position the script at the end of the document. At time of parsing, the selected elemenent does not yet exist. (There still remains an error 'rgb(0, 128, 0)' is not a valid selector in the animation of the color, but I can't help you with that.)
– ccprog
Jan 1 at 15:30
Position the script at the end of the document. At time of parsing, the selected elemenent does not yet exist. (There still remains an error 'rgb(0, 128, 0)' is not a valid selector in the animation of the color, but I can't help you with that.)
– ccprog
Jan 1 at 15:30
add a comment |
You need to import the SnapSVG library in a separate <script>
tag from the one where you defined your own code. So try closing the first <script>
tag and then opening a new one for your code, i.e.:
<script src="https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.5.1/snap.svg-min.js"></script>
<script>
// your JS code
</script>
add a comment |
You need to import the SnapSVG library in a separate <script>
tag from the one where you defined your own code. So try closing the first <script>
tag and then opening a new one for your code, i.e.:
<script src="https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.5.1/snap.svg-min.js"></script>
<script>
// your JS code
</script>
add a comment |
You need to import the SnapSVG library in a separate <script>
tag from the one where you defined your own code. So try closing the first <script>
tag and then opening a new one for your code, i.e.:
<script src="https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.5.1/snap.svg-min.js"></script>
<script>
// your JS code
</script>
You need to import the SnapSVG library in a separate <script>
tag from the one where you defined your own code. So try closing the first <script>
tag and then opening a new one for your code, i.e.:
<script src="https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.5.1/snap.svg-min.js"></script>
<script>
// your JS code
</script>
answered Jan 1 at 1:09
johnheroyjohnheroy
32615
32615
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992120%2fis-it-possible-to-use-snap-inside-an-svg%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
<script src="some url"></script> <script> some code
– Felipe Valdes
Jan 1 at 3:47