123

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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  background: #85cff4;
}

            
          
!
            
              /************************************
  This codepen is part of the svg.js
  advent calendar. You can find all
  the pens at twitter: @svg_js
*************************************/

const width = window.innerWidth
const height = window.innerHeight - 10

// Create SVG
const canvas = SVG().addTo('body')
  .size(width, height)
  .viewbox(0, 0, width, height)

// Have some text as call to action
canvas.text('Click on the water surface!')
  .font({size: 25})
  .move(20, 20)

// This is our template which we will clone later
const gradient = canvas.gradient('radial', (add) => {
  // If you want try to change the colors or offsets
  add.stop(0, '#01addd', 0)
  add.stop(0.0025, '#01addd', 0.5)
  add.stop(0.005, '#eeeeee', 0.5)
  add.stop(0.010, '#039ad3', 0.5)
  add.stop(0.015, '#eeeeee', 0.5)
  add.stop(0.0175, '#eeeeee', 0)
})

canvas.on('click', (e) => {
  // Convert mouse coordinates into canvas coordinates
  const {x, y} = canvas.point(e.clientX, e.clientY)

  drawAndAnimate(x, y)

  // You want an echo? Uncomment this!
  // setTimeout(() => drawAndAnimate(x, y), 200)
  // setTimeout(() => drawAndAnimate(x, y), 400)
})


const drawAndAnimate = (x, y) => {
  // Clone gradient and create rect with gradient
  const grad = gradient.clone().insertAfter(gradient)
  const rect = canvas.rect(width, height)
    .center(x, y)
    .fill(grad)

  // Create List of all stops in gradient and
  // create runner for each with easing set to linear
  const stops = grad.children()
    .animate(10000)
    .ease('-')

  // We update every stop explicitely
  // no need for fancy math here
  stops[0].update(0.985)
  stops[1].update(0.9875)
  stops[2].update(0.990)
  stops[3].update(0.995)
  stops[4].update(0.9975)
  stops[5].update(1)

  // Start fading out the whole thing after 3 sec
  // delay and remove rect and gradient in the end
  rect.animate(7000, 3000)
    .opacity(0)
    .after(() => {
      rect.remove()
      grad.remove()
    })
}

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console