Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="image"><img class="svg-img" src="https://d2my2wpsc41l6t.cloudfront.net/cambrian/Cambrian_Illustration_16_Business%20Homepage_Final.svg" data-anim-attach-item="[clip-path='url(#__lottie_element_143)']" data-anim-attach-point="#car-path">

              
            
!

CSS

              
                body,html{
  padding:0;
  margin:0;
}
svg{
  max-width:100%;
  width:100%;
  position:relative;
}
#anim{
  position:absolute;
  top:0;
  left:0;
  width:100%;

  
}
.image text{
  font-family:"Arial"!important;
}
.start #boat-1{
  transition:transform 80s linear;
  transform:translate3d(40rem,0,0);
  will-change:transform;
}
.start #boat-2{
  transition:transform 110s linear;
  transform:translate3d(-10rem,0,0);
  will-change:transform;
}
.start #plane{
  transition:transform 50s linear;
  transform:translate3d(60rem,-8rem,0);
  will-change:transform;
}
.grain{
  width:100%;
  height:100%;
  display:block;
  content:"";
  position:fixed;
  top:0;
  left:0;
  bottom:0;
  right:0;
  z-index:1;
  filter:url(#noiseFilter);
  opacity:.25;
  pointer-events:none;
}
.image{
  position:relative;
  z-index:-1;
}
[id*=sway]{
  transform-origin: bottom center;
  animation:slowSway 15s both infinite;
  animation-delay:calc(var(--delay)*1s);
}
g[id*="anim-hide"]{
  visibility:hidden;
}
#anim{
  pointer-events:none;
}
@keyframes slowSway{
  0%{
        transform: skew(-0.4deg, 0deg);  

  }
  50%{
        transform: skew(0.4deg, 0deg);  

  }
   100%{
        transform: skew(-0.4deg, 0deg);

  }
  
}

/*car anim*/
@keyframes rotate{
  from{
    transform:rotate(0deg)
  }
  to{
    transform:rotate(360deg)
  }
  
}
@keyframes moveLeft{
  from{
    transform:translate3d(60%,0,0)
  }
  to{
    transform:translate3d(-30%,0,0)
  }
  
}
@keyframes moveLeft2{
  from{
    transform:translate3d(0%,0,0)
  }
  to{
    transform:translate3d(-200%,0,0)
  }
  
}
@keyframes moveRight{
  from{
    transform:translate3d(-30%,0,0)
  }
  to{
    transform:translate3d(50%,0,0)
  }
  
}
@keyframes moveRight2{
  from{
    transform:translate3d(0%,0,0)
  }
  to{
    transform:translate3d(200%,0,0)
  }
  
}
svg g[id*='car'] * { 
  transform-box: fill-box;
}
svg g[id*='car_left'] { 
  animation:moveLeft 18s infinite linear; 
}
svg g[id*='car_x5F'] { 
  animation:moveLeft2 14s infinite linear; 
}
svg g[id*='car_right'] { 
  animation:moveRight 18s linear infinite; 
}
g[id*='car'] [id*="wheel"]{
  animation:rotate 3s infinite linear reverse; 
  transform-origin:center center;
}
svg g[id*='bird-anim'] { 
  animation:moveLeft2 600s infinite linear; 
}
svg g[id*='reflection-right'] { 
  animation:moveRight 300s infinite linear; 
}
@keyframes cloud1{
  to{
    transform: translate3d(104vw, 0px, 0px);
  }
}
[id*="cloud"]{
  animation:cloud1 280s linear infinite;
  animation-direction: alternate;

}
              
            
!

JS

              
                //change img into inline SVG
let attachPoint1,attachItem1,attachPoint2,attachItem2;
function convertSVG(elem){
		let $img = $(elem);
		let imgID = $img.attr('id');
		let imgClass = $img.attr('class');
		let imgURL = $img.attr('src');
    attachPoint = $img.attr('data-anim-attach-point');
    attachItem = $img.attr('data-anim-attach-item');
		$.ajax({
			url: imgURL,
			crossDomain: true,
			type: "GET",
			success: function(data) {
				var $svg = $(data).find('svg');
				if (typeof imgID !== 'undefined') { 
					$svg = $svg.attr('id', imgID);
				}
				if (typeof imgClass !== 'undefined') {
					$svg = $svg.attr('class', imgClass + ' replaced-svg');
				}
				$svg = $svg.removeAttr('xmlns:a');
				$img.replaceWith($svg);
				initActions();
			},
			cache: false
		});
}
function getRandomInt(max) {
  return Math.floor(Math.random() * max);
}


convertSVG('.svg-img');

function initActions(){
	 $('[id*="sway"]').each(function(){
      let num = getRandomInt(6)
       $(this).attr('style','--delay:'+num);
     });

  setTimeout(function(){	
    $('.replaced-svg').addClass('start');	
  },500);
    $(attachItem1).insertAfter(attachPoint1)
     $(attachItem2).insertAfter(attachPoint2)

}

let animationURL = $('#anim').attr('data-src')

function fetchAnimation(url) {
    return new Promise((resolve, reject) => {
        let xhr = new XMLHttpRequest()
        xhr.open('GET', url)
        xhr.responseType = 'json'
        xhr.onload = () => {
            resolve(xhr.response)
        }
        xhr.onerror = () => {
            reject()
        }
        xhr.send()
    })
}

async function playAnimation(animUrl,container,loop) {
    let anim = await fetchAnimation(animUrl)
    animObject = lottie.loadAnimation({
        container: document.getElementById(container), 
        renderer: "svg",
        loop: true,
        autoplay: false,
        animationData: anim
    });
  return animObject;
}

(async() => {
   let animation = await playAnimation(animationURL,"anim",false)
   animation.play()
   /* do other stuff here and after */
})()
              
            
!
999px

Console