SVG - circle rotating around circle - css

I have two circles, one just an outline, and one filled in.
<svg width="300" height="300" style="border: 1px solid black">
<circle stroke="black" stroke-width="1" r="100" cx="150" cy="150" fill="white"></circle>
<circle r="10" cx ="50" cy="150"></circle>
</svg>
I want the filled-in circle to rotate around the other circle. How can I do this? A css/svg only solution would be great, as this will be a .svg file, not a .html file.

So, I decided to try using only HTML and CSS for this.
.inner {
margin: 0 auto;
height: 250px;
width: 250px;
border-radius: 100%;
border: 1px solid black;
position: relative;
}
.outter {
height: 20px;
width: 20px;
border-radius: 100%;
background: black;
position: absolute;
top: 115px;
left: 115px;
animation: spin 5s linear infinite;
}
#keyframes spin {
from {
transform: rotate(0deg) translate(125px);
}
to {
transform: rotate(360deg) translate(125px);
}
}
<div class="inner">
<div class="outter"></div>
</div>
Hope it helps.
Regards
EDITED: Made with SVG.
.outter {
transform-origin: 150px 150px;
animation: spin 5s infinite linear;
}
#keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
<svg width="300" height="300" style="border: 1px solid black">
<circle stroke="black" stroke-width="1" r="100" cx="150" cy="150" fill="white"></circle>
<circle class="outter" r="10" cx ="50" cy="150"></circle>
</svg>

You could also use a svg SMIL animation like <animateTransform>
<svg width="300" height="300" style="border: 1px solid black">
<circle stroke="black" stroke-width="1" r="100" cx="150" cy="150" fill="white" />
<circle id="dot" r="10" cx="50" cy="150" />
<animateTransform href="#dot" attributeName="transform" type="rotate" from="0 150 150" to="360 150 150" dur="3s" repeatCount="indefinite" />
</svg>
The above <animateTransform> values translates to these transformation attributes:
From
transform="rotate(0 150 150)"
to
transform="rotate(360 150 150)"
Unlike its css counterpart svg's rotate() accepts 3 arguments
rotation angle (mandatory)
transform origin x
transform origin y
This way we can define the pivot point – in this case the center of our circle/svg.
Probably the main benefit of SMIL animations: they will also play in <img> elements and background-images.
This concept is often used for loading spinner svgs.

Related

Why does the svg shape dissapear after setting the transform-origin to 50%? [duplicate]

This question already has an answer here:
How to use transform-origin in conjunction with SVGs? [duplicate]
(1 answer)
Closed last month.
Transform-origin 50% 50% sets the center of scaling to the center of the element. So when I scale the element, it should just scale from the circles center meaning, the viewbox stays in place, and only the element scales from the elements center, but that's not what is happening. Is this actually setting the point of origin for the whole viewbox of the element?
svg{
border: 1px solid red;
}
circle{
fill: red;
fill-opacity: 50%;
stroke: red;
stroke-width: 1px;
}
circle:hover{
transform:scale(2);
transform-origin: 50% 50%;
}
<svg width="800" height="600" viewBox="0 0 800 600">
<circle cx="50" cy="50" r="20"/>
</svg>
Here, I tried to explain both the problem and possible solution. I have considered 50px 50px in the transform. Because, it is the dimension of the circle. Hope this helps.. Good luck!
svg {
border: 1px solid red;
}
circle {
fill: red;
fill-opacity: 50%;
stroke: red;
stroke-width: 1px;
}
.problem circle:hover {
transform: scale(2);
transform-origin: 50% 50%;
}
.solution circle:hover {
transform: scale(2);
transform-origin: 50px 50px;
}
<svg class="problem" width="200" height="200" viewBox="0 0 200 200">
<circle cx="50" cy="50" r="20"/>
</svg>
<svg class="solution" width="200" height="200" viewBox="0 0 200 200">
<circle cx="50" cy="50" r="20"/>
</svg>

Assign a pattern to the whole page but reveal it only on some shapes, the rest should be black

I would like to create a web page where the background is flat black but I need to add also a background pattern that should be visible only inside some shapes (circles in this simple example, but they will be a complicated path, different for each section).
I know I could assign the pattern to the shapes, but I need also to animate the shapes and is not possible to animate the pattern.
Here my starting code
I applied a texture in CSS to the entire page and I add some circles.
Now I need to "hide" the texture everywhere except inside the shapes. And the page background should be black.
How can I do that?
Is this the sort of thing you are after?
/* hide the SVG */
svg#pattern {
position: absolute;
left: -9999px;
}
body {
background-color: black;
height: 2000px;
color: white;
}
section {
height: 400px;
}
circle {
animation: throb 1s infinite;
}
#keyframes throb {
0% { r: 48px; }
50% { r: 30px; }
100% { r: 48px; }
}
<svg id="pattern">
<defs>
<pattern id="check" width="10" height="10" patternUnits="userSpaceOnUse">
<rect width="10" height="10" fill="linen"/>
<rect width="5" height="5" fill="black"/>
<rect x="5" y="5" width="5" height="5" fill="black"/>
</pattern>
</defs>
</svg>
<div>
<h1>Test page</h1>
<section>
<svg width="400" height="100">
<circle cx="50" cy="50" r="48" fill="url(#check)"/>
</svg>
</section>
<section>
<svg width="400" height="100">
<circle cx="50" cy="50" r="48" fill="url(#check)"/>
</svg>
</section>
<section>
<svg width="400" height="100">
<circle cx="50" cy="50" r="48" fill="url(#check)"/>
</svg>
</section>
</div>
body {
background-color: black;
}
.container {
opacity: 0.8;
background-image: linear-gradient(135deg, black 25%, transparent 25%), linear-gradient(225deg, black 25%, transparent 25%), linear-gradient(45deg, black 25%, transparent 25%), linear-gradient(315deg, black 25%, #e5e5f7 25%);
background-position: 10px 0, 10px 0, 0 0, 0 0;
background-size: 10px 10px;
background-repeat: repeat;
width:200px;
height:200px;
}
<div class="container" style='clip-path: url("#test");'></div>
<svg x="0" y="0" width="0" height="0">
<clipPath id="test">
<circle cx="100" cy="100" r="20" fill="red"></circle>
</clipPath>
</svg>

How to rotate multiple SVG reused elements around same origin?

How can I rotate 3 irregular SVG circles around same origin? They are written as a path and reused. I have set transform-origin to center, what else am I missing? They should all be in the same space and overlap in center like in this image
<svg width="900" height="500" viewBox="0 0 900 500">
<defs>
<path id="circle" d="m 43.467262,110.65774 c -2.81733,25.95379 9.663408,54.24201 33.479611,66.3315 12.768318,6.52194 29.493997,6.26667 40.854417,-3.07058 12.79824,-9.29014 25.48168,-19.76411 33.26937,-33.78136 4.54432,-8.49226 5.12542,-19.52979 -0.73083,-27.56368 C 142.27364,100.40343 128.56364,93.579328 115.25185,88.674523 98.350761,82.775856 78.939082,80.223234 62.116925,87.733369 52.940099,92.163321 45.975566,100.79364 43.467262,110.65774 Z" />
</defs>
<g class="group">
<use class="circle circle--1" xlink:href="#circle" />
<use class="circle circle--2" xlink:href="#circle" />
<use class="circle circle--3" xlink:href="#circle" />
</g>
</svg>
svg {
width: 900px;
path {
stroke: #333;
stroke-width: 3px;
fill: transparent;
}
}
g {
position: relative;
transform-origin: center center;
}
.circle {
transform-origin: 50% 50%;
perspective: 500px;
&--1 {
transform: rotateZ(60deg);
}
&--2 {
transform: rotateZ(120deg);
}
&--3 {
transform: rotateZ(180deg);
}
}
https://codepen.io/anon/pen/mQdLvX
You want transform-box: fill-box; i.e.
.circle {
transform-box: fill-box;
transform-origin: 50% 50%;
perspective: 500px;
&--1 {
transform: rotateZ(60deg);
}
&--2 {
transform: rotateZ(120deg);
}
&--3 {
transform: rotateZ(180deg);
}
}
When the svg draw is not centered on the canvas, this gets a bit more difficult. I've ajusted the SVG viewBox values, take a look at the following snippet:
svg {
border: 1px solid red;
}
svg path {
stroke: #333;
stroke-width: 3px;
fill: transparent;
}
.circle {
transform-origin: 50% 50%;
}
.circle--1 {
transform: rotateZ(90deg);
}
.circle--2 {
transform: rotateZ(160deg);
}
.circle--3 {
transform: rotateZ(270deg);
}
<svg width="900" height="500" viewBox="0 0 250 250">
<defs>
<path id="circle" d="m 43.467262,110.65774 c -2.81733,25.95379 9.663408,54.24201 33.479611,66.3315 12.768318,6.52194 29.493997,6.26667 40.854417,-3.07058 12.79824,-9.29014 25.48168,-19.76411 33.26937,-33.78136 4.54432,-8.49226 5.12542,-19.52979 -0.73083,-27.56368 C 142.27364,100.40343 128.56364,93.579328 115.25185,88.674523 98.350761,82.775856 78.939082,80.223234 62.116925,87.733369 52.940099,92.163321 45.975566,100.79364 43.467262,110.65774 Z" />
</defs>
<g class="group">
<use class="circle circle--1" xlink:href="#circle" />
<use class="circle circle--2" xlink:href="#circle" />
<use class="circle circle--3" xlink:href="#circle" />
</g>
</svg>

SVG progress bar

I have a requirement where I need to load js files dynamically and show the progress of loading files through a SVG icon. The SVG icon will act as progress bar where it fills with a color from bottom to top, linearly.
Here is the codepen
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="79.36px" height="93.844px" viewBox="0 0 79.36 93.844">
<path fill="transparent" stroke="black" d="M50,2C30-4,8,7,2,28c-6,20,5,42,26,48h0l-4,15l33-18c0-0,0-0,1-0l0-0l-0-0c8-4,15-12,17-22C83,30,71,8,50,2z" />
</svg>
I am planning to make this icon independent such that I will only pass the percentage value dynamically.
I somehow able to get the animation done but unable to keep the border or outline of the svg. Here is the code.
#progressMove {
transition: .3s y;
}
#progressMove:hover {
y: 60%;
}
<svg id="kenseoProgress" width="79.36px" height="93.844px" viewBox="0 0 79.36 93.844">
<defs>
<mask id="bubbleKenseo">
<path fill="red" stroke="black" d="M50,2C30-4,8,7,2,28c-6,20,5,42,26,48h0l-4,15l33-18c0-0,0-0,1-0l0-0l-0-0c8-4,15-12,17-22C83,30,71,8,50,2z" />
</mask>
</defs>
<g x="0" y="0" width="79.36px" height="93.844px" mask="url(#bubbleKenseo)" height="100">
<rect id="progressMove" x="0" y="0%" width="100%" height="100%" fill="blue" stroke="black" />
</g>
</svg>
So, the problems I have are:
Unable to maintain the border to the SVG
Whatever the color I add is having some kind of opacity which I am unable to remove.
Edit: Browser compatibility: IE11+, chrome, safari and firefox
PS: I don't want to use SMIL animations.
CHROME/SAFARI SOLUTION
Using the CSS property transform and counter-increment you can achieve the fill and number increment.
jsFiddle
CODE SNIPPET
for (var i = 0; i < 100; i++) {
setTimeout(function() {
$(".progress-container p").append("<span>");
}, i * 20);
}
pattern #progressMove {
transform: translateY(100%);
color: purple;
animation: progressBar 2s steps(100, end) forwards;
}
#keyframes progressBar {
to {
transform: translateY(0);
}
}
.progress-container {
margin: 0;
display: inline-block;
position: relative;
counter-reset: progress;
}
.progress-container figcaption {
position: absolute;
top: 40%;
left: 50%;
transform: translate(-40%, -50%);
}
.progress-container p {
margin: 0;
font-weight: bold;
}
.progress-container span {
counter-increment: progress;
}
.progress-container p::after {
content: counter(progress)"%";
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<figure class="progress-container">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="79.36px" height="93.844px" viewBox="0 0 79.36 93.844">
<pattern id="progress" x="0" y="0" width="79.36" height="93.844" patternUnits="userSpaceOnUse">
<rect id="progressMove" x="0" y="0" width="100%" height="100%" stroke="none" fill="currentColor" />
</pattern>
<path fill="url(#progress)" stroke="#000" d="M50,2C30-4,8,7,2,28c-6,20,5,42,26,48h0l-4,15l33-18c0-0,0-0,1-0l0-0l-0-0c8-4,15-12,17-22C83,30,71,8,50,2z" />
</svg>
<figcaption>
<p>
</p>
</figcaption>
</figure>
Note:
Will update if I can give a better solution to cover browser support.
EDIT:
Based on Persijn answer, you will as well have to change the color of the background to that of its parent.
The whole component would be the figure element, sadly the symbol in the spritesheet will only be used to provide the path and background.
Note: jQuery removed in this version.
jsFiddle
for (var i = 0; i < 100; i++) {
setTimeout(function() {
var progressCounter = document.querySelector(".progress__counter"),
number = document.createElement("span");
progressCounter.appendChild(number);
}, i * 20);
}
#spritesheet {
display: none;
}
.icon {
display: inline-block;
width: 1em;
height: 1em;
}
.icon-bubble {
font-size: 7em;
color: white;
}
.progress-container {
margin: 0;
display: inline-block;
position: relative;
counter-reset: progress;
overflow: hidden;
line-height: 0;
}
.progress__inner {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
}
.progress__fill {
background-color: purple;
height: 100%;
transform: translateY(100%);
animation: progressFill 2s steps(100, end) forwards;
}
#keyframes progressFill {
to {
transform: translateY(0);
}
}
.progress__counter {
position: absolute;
top: 40%;
left: 50%;
transform: translate(-40%, -50%);
margin: 0;
font-weight: bold;
}
.progress__counter span {
counter-increment: progress;
}
.progress__counter::after {
content: counter(progress)"%";
}
<figure class="progress-container">
<svg class="icon icon-bubble">
<use xlink:href="#icon-bubble"></use>
</svg>
<figcaption class="progress__inner">
<div class="progress__fill"></div>
<p class="progress__counter"></p>
</figcaption>
</figure>
<svg id="spritesheet">
<symbol id="icon-bubble" viewBox="0 0 79.36 93.844">
<title>Loading Bubble</title>
<path id="bubble-cover" fill="currentColor" stroke="#000" d="M-10,-10 100,-10 100,100 -10,100 -10,-10 50,2C30-4,8,7,2,28c-6,20,5,42,26,48h0l-4,15l33-18c0-0,0-0,1-0l0-0l-0-0c8-4,15-12,17-22C83,30,71,8,50,2z" />
</symbol>
</svg>
TESTS:
Chrome 53
IE10
Edge
FireFox 47
IOS 10 Safari
PLAYGROUND
jsFiddle
for (var i = 0; i < 100; i++) {
setTimeout(function() {
var progressCounter = document.querySelector(".progress__counter"),
number = document.createElement("span");
progressCounter.appendChild(number);
}, i * 20);
}
#spritesheet {
display: none;
}
.icon {
display: inline-block;
width: 1em;
height: 1em;
}
.icon-bubble {
font-size: 7em;
color: white;
}
.progress-container {
margin: 0;
display: inline-block;
position: relative;
counter-reset: progress;
overflow: hidden;
line-height: 0;
}
.progress__inner {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
}
.progress__fill {
background-color: purple;
height: 100%;
transform: translateY(100%);
animation: progressFill 2s steps(100, end) forwards, progressFillColor 100ms linear 2s forwards;
position: relative;
}
#keyframes progressFill {
to {
transform: translateY(0);
}
}
#keyframes progressFillColor {
to {
background-color: green;
}
}
.progress__counter {
position: absolute;
top: 40%;
transform: translateY(-40%);
text-align: center;
width: 100%;
margin: 0;
font-weight: bold;
animation: progressCounter 100ms linear 1s forwards;
}
.progress__counter span {
counter-increment: progress;
}
.progress__counter::after {
content: counter(progress)"%";
animation: progressCounterCompleted 1s linear 2s forwards;
}
#keyframes progressCounter {
to {
color: white;
}
}
/* Chrome Only*/
#keyframes progressCounterCompleted {
33% {
content: "File(s)";
}
66% {
content: "Uploaded";
}
100% {
content: "Successfully!";
}
}
<figure class="progress-container">
<svg class="icon icon-bubble">
<use xlink:href="#icon-bubble"></use>
</svg>
<figcaption class="progress__inner">
<div class="progress__fill"></div>
<p class="progress__counter"></p>
</figcaption>
</figure>
<svg id="spritesheet">
<symbol id="icon-bubble" viewBox="0 0 79.36 93.844">
<title>Loading Bubble</title>
<path id="bubble-cover" fill="currentColor" stroke="#000" d="M-10,-10 100,-10 100,100 -10,100 -10,-10 50,2C30-4,8,7,2,28c-6,20,5,42,26,48h0l-4,15l33-18c0-0,0-0,1-0l0-0l-0-0c8-4,15-12,17-22C83,30,71,8,50,2z" />
</symbol>
</svg>
SVG with pattern and y transition:
svg:hover pattern #fillshape {
y: 0%;
}
pattern #fillshape {
transition: y 1s;
y: 100%;
}
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="79.36px" height="93.844px" viewBox="0 0 79.36 93.844">
<pattern id="pattern1"
x="0" y="0" width="79.36" height="93.844"
patternUnits="userSpaceOnUse" >
<rect id="fillshape" x="0" y="0" width="100%" height="200%" stroke="none" fill="purple" />
</pattern>
<path fill="url(#pattern1)" stroke="black" d="M50,2C30-4,8,7,2,28c-6,20,5,42,26,48h0l-4,15l33-18c0-0,0-0,1-0l0-0l-0-0c8-4,15-12,17-22C83,30,71,8,50,2z" />
</svg>
Now this does not work in Firefox or Edge. It does not recognize x and y as CSS properties...
Here is a solution that uses a div behind the svg shape.
The downside of this solution is that the svg shape gets a background eg. if you want the shape only you would have to match the background color of the shape with that of the background of the page.
svg {
position: relative;
}
.spesial {
width: 90px;
height: 0px;
display: inline-block;
background-color: purple;
margin-left: -100px;
transition: height 1s;
}
svg:hover + .spesial {
height: 100px;
}
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="100" height="100" viewBox="0 0 75 90">
<path stroke="black" fill="gray" d="M-10,-10 100,-10 100,100 -10,100 -10,-10 50,2C30-4,8,7,2,28c-6,20,5,42,26,48h0l-4,15l33-18c0-0,0-0,1-0l0-0l-0-0c8-4,15-12,17-22C83,30,71,8,50,2z" />
</svg>
<div class="spesial">
</div>
First off, you want to use clip-path, or set the mask fill to white for 100% opacity: mask is used as a greyscale alpha channel and the red fill color causes the opacity change.
As for the stroke, you want to add it as a separate element that is not affected by the clipping. (You can probably re-use the path with defs and use, I just copy-pasted it here)
#progressMove {
transition: .3s y;
}
#progressMove:hover {
y: 60%;
}
<svg id="kenseoProgress" width="79.36px" height="93.844px" viewBox="0 0 79.36 93.844">
<defs>
<clipPath id="bubbleKenseo">
<path d="M50,2C30-4,8,7,2,28c-6,20,5,42,26,48h0l-4,15l33-18c0-0,0-0,1-0l0-0l-0-0c8-4,15-12,17-22C83,30,71,8,50,2z" />
</clipPath>
</defs>
<path stroke="black" stroke-width="1" fill="transparent" d="M50,2C30-4,8,7,2,28c-6,20,5,42,26,48h0l-4,15l33-18c0-0,0-0,1-0l0-0l-0-0c8-4,15-12,17-22C83,30,71,8,50,2z" />
<g x="0" y="0" width="79.36px" height="93.844px" clip-path="url(#bubbleKenseo)" height="100">
<rect id="progressMove" x="0" y="0%" width="100%" height="100%" fill="blue" stroke="black" />
</g>
</svg>
var prObject = document.getElementById("prObject"),
prDom = document.getElementById("progressMove"),
prValue = 0;
prObject.onmouseenter = function() {
prDom.setAttribute('class', 'prHover')
};
prObject.onmouseleave = function() {
prDom.removeAttribute('class')
};
/*prDom.setAttributeNS(null, 'y', '0');*/
var cTimer = setInterval(function() {
prValue += 20.6;
prDom.style.transform = "translateY(" + [100 - Math.min(prValue, 100)] + "%)";
if (prValue >= 100) {
clearInterval(cTimer);
}
}, 450);
#progressMove {
transition: transform 0.20s linear;
}
#progressMove.prHover {
transform: translateY(40%) !important;
}
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<svg id="kenseoProgress" width="79.36px" height="93.844px" viewBox="0 0 79.36 93.844">
<defs>
<path id="mypath" fill="white" d="M50,2C30-4,8,7,2,28c-6,20,5,42,26,48h0l-4,15l33-18c0-0,0-0,1-0l0-0l-0-0c8-4,15-12,17-22C83,30,71,8,50,2z" />
<mask id="bubbleKenseo">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#mypath"></use>
</mask>
</defs>
<g x="0" y="0" width="79.36px" height="93.844px" mask="url(#bubbleKenseo)" height="100" stroke-width="0">
<rect id="progressMove" x="0" y="0" width="100%" height="100%" fill="blue" stroke="black" style="transform: translateY(100%);" />
</g>
<g id="prObject" x="0" y="0" width="79.36px" height="93.844px" height="100" fill-opacity="0" stroke="black" stroke-width="0.5px">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#mypath"></use>
</g>
</svg>
</body>
</html>

Animation of multiple background image positions via keyframes works in Chrome & Safari but not Firefox

The goal is to create an infinitely scrolling, two-layer parallax background. The effect works perfectly in Mac Chrome and Safari, but it stutters in Firefox. Any ideas why? Thanks!
<style>
body {
background-color: black;
}
#container {
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
}
#-webkit-keyframes scroll {
100% {
background-position: 0 0;
}
}
#keyframes scroll {
100% {
background-position: 0 0;
}
}
.bg1 {
-webkit-animation: scroll 2.5s linear infinite;
animation: scroll 2.5s linear infinite;
background-image: url(path/to/image);
background-position: 0 -156px;
background-size: 128px 156px;
height: 100%;
opacity: 0.5;
position: fixed;
width: 100%;
}
.bg2 {
-webkit-animation: scroll 5s linear infinite;
animation: scroll 5s linear infinite;
background-image: url(path/to/image);
background-position: 0 -78px;
background-size: 64px 78px;
height: 100%;
opacity: 0.25;
position: fixed;
width: 100%;
}
</style>
<body>
<div id="container">
<div id="bg1" class="bg1"></div>
<div id="bg2" class="bg2"></div>
</div>
</body>
You don't have any -moz- properties in your code.
-webkit- is supported in chrome and safari both.
But for firefox you should have -moz-prefix in some old versions.
I was able to get around Firefox's engine not being to keep up with tandem animations of full-window divs of repeating backgrounds…by instead switching to two animated, patterned, full-window SVGs.
So rather than adding keyframe animations to divs in my CSS, I instead used the following markup in my HTML:
<svg id="parallax2" width="100%" height="200%" style="display: none;">
<defs>
<pattern id="pattern2" patternUnits="userSpaceOnUse" height="100" width="100">
<image x="-40" y="-40" height="100" width="100" xlink:href="path/to/image"></image>
</pattern>
</defs>
<rect width="100%" height="200%" fill="url(#pattern2)">
<animateTransform
attributeName="transform"
type="translate"
from="0 -50"
to="0 50"
dur="3750ms"
repeatCount="indefinite"
/>
</rect>
</svg>
<svg id="parallax1" width="100%" height="200%" style="display: none;">
<defs>
<pattern id="pattern1" patternUnits="userSpaceOnUse" height="200" width="200">
<image x="-40" y="-40" height="200" width="200" xlink:href="path/to/image"></image>
</pattern>
</defs>
<rect width="100%" height="200%" fill="url(#pattern1)">
<animateTransform
attributeName="transform"
type="translate"
from="0 -100"
to="0 100"
dur="3750ms"
repeatCount="indefinite"
/>
</rect>
</svg>

Resources