cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

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.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

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.

            
              <div class="controls">
  <label for="spacing">
    <a href="https://www.poetryfoundation.org/poetrymagazine/poems/12744/trees">
        I think that I shall never see <br>
    An SVG as lovely as a tree.
      
    </a>
  </label>
    <input id="leafColors" type="range" name="spacing" min="10" max="400" value="10" data-sizing="px" list="months">
    <datalist id="months">
      <option value="50" label="May">
      <option value="100" label="June">
      <option value="150" label="July">
      <option value="200" label="August">
      <option value="250" label="September">
      <option value="300" label="October">
      <option value="350" label="November">
      <option value="400" label="December">
    </datalist>
</div>

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" x="0px" y="0px" viewBox="0 0 100 125" enable-background="new 0 0 100 100" xml:space="preserve">
  <g>
    <path class="trunk" d="M54.061,63.392c-0.044-1.116-0.344-3.345,1.392-5.507c4.576-5.702,8.979-10.163,9.253-26.052   c-1.148,10.625-4.061,18.225-10.284,21.92c-0.364,0.216-1.123,0.68-1.225-0.8c-0.704-10.068-1.078-21.004-1.91-31.592   c-0.964,12.27-1.281,25.139-2.253,36.321c-0.125,1.434-0.513,2.274-2.038,1.383c-3.459-2.018-8.333-9.051-10.919-19.509   c0.632,9.769,4.325,19.462,10.077,23.785c2.197,1.651,1.863,3.925,1.782,4.967c-1.039,13.372-3.818,19.055-8.43,23.091   c5.564-2.946,11.455-1.31,11.782,3.6c0.982-5.891,6.546-6.546,11.784-3.6C57.768,86.761,54.692,79.732,54.061,63.392z"/>
    <path class="leaf" d="M59.624,27.335c-1.257,4.608-0.196,9.315,2.493,12.667c0.343-2.577,0.686-8.931,5.496-13.57   c-2.405,5.325-2.748,11.854-2.405,15.116c5.862-1.933,8.098-4.862,9.43-8.384c2.718-7.183,0.304-14.388-1.724-18.667   C65.03,17.198,60.976,22.378,59.624,27.335z"/>
    <path class="leaf" d="M49.726,30.732c-0.15-4.987,1.075-12.031,1.566-14.263c0.352,2.772,1.717,8.932,1.455,13.801   c3.592-3.352,5.124-7.571,5.074-10.628C57.703,12.548,53.767,8.154,50.838,5c-4.955,4.055-7.182,10.036-7.138,15.093   C43.741,24.805,45.755,28.579,49.726,30.732z"/>
    <path class="leaf" d="M35.765,46.866c-0.067-2.616-0.633-7.779-3.653-13.054c1.966,1.362,5.701,5.289,7.169,11.548   c2.75-4.697,2.868-8.492,1.651-11.718c-2.761-7.322-13.295-12.162-17.35-13.514c-2.027,6.083-2.253,15.092,1.576,20.499   C27.318,43.675,30.913,45.594,35.765,46.866z"/>
    <path class="leaf" d="M39.964,24.835c-0.477-2.1-1.495-5.977-2.911-8.204c1.6,1.6,3.26,5.203,4.147,7.581c1.576-3.865,1.314-6.691-0.014-8.717   c-1.836-2.802-5.441-4.152-8.37-4.828c-1.125,2.478-1.721,6.695,0.048,9.696C34.235,22.687,36.641,24.256,39.964,24.835z"/>
    <path class="leaf" d="M21.311,42.143c0,0,2.418,2.048,4.051,4.284c0.379-2.133-0.076-3.719-0.878-5.126c-2.064-3.623-5.632-4.28-7.435-4.505   c-0.225,2.252-0.461,5.413,1.089,7.523c1.435,1.955,3.732,2.977,6.337,3.193C23.942,46.262,22.884,44.062,21.311,42.143z"/>
    <path class="leaf" d="M62.162,12.897c-0.334,2.051-0.578,4.435-0.708,6.202c2.355-1.155,3.577-2.489,4.139-3.883   c1.343-3.333-0.789-5.676-1.914-7.929c-2.479,1.126-5.146,2.932-5.591,5.896c-0.272,1.814,0.336,3.766,2.207,5.763   C60.61,17.852,61.19,15.913,62.162,12.897z"/>
    <path class="leaf" d="M58.377,37.918c-4.922,3.646-6.181,8.337-3.369,12.325c0.582-1.111,1.634-3.48,2.385-7.239   c0.089,3.063-0.633,5.773-1.279,7.492C59.787,48.812,61.793,45.736,58.377,37.918z"/>
    <path class="leaf" d="M46.715,53.582c4.451-6.78,0.429-11.923-2.9-15.315c-3.422,5.512-5.635,12.378,1.583,15.509   c-0.766-2.214-1.219-5.313-0.758-8.99C44.911,48.946,46.025,52.024,46.715,53.582z"/>
    <path class="leaf" d="M81.473,28.237c-2.252,1.801-5.368,4.102-6.618,7.927c-0.531,1.626-0.466,3.499,0.714,5.846   c1.054-1.302,2.916-3.955,3.717-7.28c0,0-0.392,5.152-2.625,7.996c2.096-0.107,3.836-1.276,5.039-3.079   C83.926,36.308,83.276,32.066,81.473,28.237z"/>
    <path class="leaf" d="M59.885,58.378c2.204-1.852,6.702-4.966,12.735-5.72c-3.848,1.268-8.811,5.465-11.493,8.464   c3.969,0.726,8.227,0.374,11.85-1.451c5.097-2.569,8.046-7.557,8.722-15.441c-4.506,0.451-10.846-0.106-16.67,4.055   C62.452,50.125,60.491,53.85,59.885,58.378z"/>
    <path class="leaf" d="M27.804,54.44c4.932,0.724,10.431,3.122,13.923,5.484c-2.878-6.245-6.396-8.743-9.98-9.808   c-5.125-1.523-9.065-1.157-12.445-0.932c0.902,5.182,3.052,9.656,7.223,11.686c4.85,2.362,10.507,2.047,14.061,1.098   C38.21,60.157,33.403,56.776,27.804,54.44z"/>
  </g>
  <text x="0" y="105" font-size="3px" font-weight="bold" font-family="'Helvetica Neue', Helvetica, Arial-Unicode, Arial, Sans-serif">Tree created by Alena Artemova</text>
  <text x="0" y="108" font-size="3px" font-weight="bold" font-family="'Helvetica Neue', Helvetica, Arial-Unicode, Arial, Sans-serif">from the Noun Project</text>
</svg>
            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=Amatic+SC');

:root {
  --leaf: #9BC53D;
  --trunk: #764134;
  --sky: #DCEDFF;
  --bodytext: #493B2A;
}

body {
  margin: 0;
  background: var(--sky);
  color: var(--bodytext);
  font-family: 'Amatic SC', sans-serif;
}

a {
  text-decoration: none;
  color: var(--leaf);
}

text {
  fill: var(--bodytext);
}

.controls {
  display: flex;
  justify-content: center;
  flex-direction: column;
  align-items: center;
  text-transform: uppercase;
  margin: 30px 0 0;
}

#leafColors {
  width: 400px;
}

.controls label {
  margin-bottom: 10px;
  font-size: 46px;
  text-align: center;
}

svg {
  width: 50%;
  margin: 0 auto;
  display: block;
  min-width: 400px;
}

.leaf {
  fill: var(--leaf);
  transform: translateY(0);
  transition: transform 1s;
}

.leaf.loose {
  transform: translateY(200%);
  transition: transform 1s;
}

.trunk {
  fill: var(--trunk);
}
            
          
!
            
              const control = document.querySelector('#leafColors')
const leaves = document.querySelectorAll('.leaf');

const setLeaf = (color) => {
  document.documentElement.style.setProperty(`--leaf`, color);
}

const loseLeaves = () => {
  leaves.forEach((leaf) => {
    leaf.classList.add('loose');
  })
  control.addEventListener('change', reset);
  return;
}
const reset = () => {
  leaves.forEach((leaf) => {
    leaf.classList.remove('loose');
  })
}

function handleUpdate() {
  const val = this.value
  if (val < 49) {
    setLeaf('#9BC53D');
  } else if (val >= 50 && val < 99) {
    setLeaf('#B2BD7E');
  } else if (val >= 100 && val < 149) {
    setLeaf('#8CAE68');
  } else if (val >= 150 && val < 199) {
    setLeaf('#60992D');
  } else if (val >= 200 && val < 249) {
    setLeaf('#447604');
  } else if (val >= 250 && val < 299) {
    setLeaf('#EA9010');
  } else if (val >= 300 && val < 349) {
    setLeaf('#CD8B76');
  } else if (val >= 350 && val < 385) {
    setLeaf('#493B2A');
  } else if (val >= 386) {
    setLeaf('#493B2A');
    loseLeaves();
  }
}

control.addEventListener('change', handleUpdate);
control.addEventListener('mousemove', handleUpdate);
            
          
!
999px
Loading ..................

Console