One interesting approach is to replicate the background to create a seamless loop effect. While this may not be the most efficient solution, it's a technique that I have personally found effective in the past.
To begin, we'll duplicate the background SVG with identical properties and refer to it as #back
instead of #front
.
keyframes frontScroll {
from {transform: translateX(0);}
to {transform: translateX(100%);}
}
keyframes backScroll {
from {transform: translateX(-100%);}
to {transform: translateX(0%);}
}
Next, we define an animation with the same properties as the original one, but it moves from -100%
to 0%
, while the original animation goes from 0%
to 100%
.
By combining these elements, here's what happens:
body {
margin : 0;
overflow : hidden;
}
#front {
position : absolute;
left :0;
right:0;
bottom:0;
z-index : 9;
-webkit-animation: frontScroll 2.5s linear infinite;
animation: frontScroll 2.5s linear infinite;
}
#back {
position: absolute;
bottom: 0;
right: 0;
left: 0;
z-index: 9
-webkit-animation: backScroll 2.5s linear infinite;
animation: backScroll 2.5s linear infinite;
}
keyframes frontScroll {
from {transform: translateX(0); }
to {transform: translateX(100%); }
}
@-webkit-keyframes frontScroll {
from {transform: translateX(0); }
to {transform: translateX(100%); }
}
keyframes backScroll {
from {transform: translateX(-100%); }
to {transform: translateX(0%); }
}
@-webkit-keyframes backScroll {
from {transform: translateX(-100%); }
to {transform: translateX(0%); }
}
<div id="back">
<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" id="Calque_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 1200 313.9" xml:space="preserve">
<style type="text/css">
.st0{fill:#602700;}
</style>
<g id="XMLID_171_">
<g id="XMLID_173_">
<g id="XMLID_193_">
<g id="XMLID_202_">
... (SVG paths content)
</g>
</g>
</g>
</svg>
</div>
<div id="front">
<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" id="Calque_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 1200 313.9" xml:space="preserve">
<style type="text/css">
.st0{fill:#602700;}
</style>
<g id="XMLID_171_">
<g id="XMLID_173_">
<g id="XMLID_193_">
<g id="XMLID_202_">
... (SVG paths content)
</g>
</g>
</g>
</g>
</svg>
</div>
By overlaying a moving car or similar object on top of the road, you can achieve the illusion of an endless driving scene.