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.

            
              <div class="svg-container">
  <svg class="scene" version="1.1" id="svg2" inkscape:version="0.91 r13725" sodipodi:docname="Domestic_Dromedary_silhouette.svg" xmlns:svg="http://www.w3.org/2000/svg" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
    x="0px" y="0px" viewBox="0 80 500 500" xml:space="preserve">
  <line id="transform-this-line" class="line" x1="0" y1="346.5" x2="500" y2="346.5"/>
  <line id="transform-straight" class="transform" x1="0" y1="346.5" x2="500" y2="346.5"/>
    <path id="transform-wavy" class="transform" d="M0,326.5c23.1,0,23.1,40,46.1,40c23.1,0,23.1-40,46.2-40c23.1,0,23.1,40,46.2,40c23.1,0,23.1-40,46.2-40
			c23.1,0,23.1,40,46.2,40c23.1,0,23.1-40,46.2-40c23.1,0,23.1,40,46.2,40c23.1,0,23.1-40,46.2-40c23.1,0,23.1,40,46.2,40
			c23.1,0,23.1-40,46.2-40c23.1,0,23.1,40,46.2,40c23.1,0,23.1-40,46.2-40c23.1,0,23.1,40,46.2,40"/>
  <path id="transform-circle" class="transform" d="M111.2,300.5c19.3-56,72.5-96.3,135-96.3c78.9,0,142.8,63.9,142.8,142.8s-63.9,142.8-142.8,142.8
                                   c-61.8,0-114.5-39.3-134.3-94.3"/>

</svg>
</div>

<div id="controls"></div>
            
          
!
            
              @width: 320px;
@color-accent: hsl(100, 75%, 75%);

body {
 margin:0;
 background: #333;
  color: #ccc;
  font-size: 16px;
  line-height: 1.5;
}
.svg-container{
  @padding: 20px;
  position: relative;
  margin: 20px auto;
  width: (@width + @padding * 2);
  border: @padding solid transparent;
  display: block;
  overflow: hidden;
  background: #222;
  .scene{
    position: relative;
  }
  .line{
    fill: transparent;
    stroke: #ccc;
    stroke-width: 3px;
    animation-iteration-count: infinite;
    animation-timing-function: linear;
    animation-fill-mode: both;
    transition: none 0.3s linear;
    transition-property: transform, stroke;
    transform-origin: 50% 69.3%;
    &.animation-wavy{
      animation-name: a-wavy;
      animation-duration: 1s;
      transform-origin: 0% 69.3%;
      stroke: #800;
      @keyframes a-wavy {
        0% {
          transform: none;
        }
        100% {
          transform: translateX(percentage(-2 / 12 - 0.017));
        }
      }
    }
    &.animation-circle{
      animation-name: a-rotating;
      animation-duration: 2s;
      transform-origin: 50% 69.3%;
      stroke-width: 5px;
      @keyframes a-rotating {
        0% {
          transform: none;
        }
        100% {
          transform: rotate(360deg);
        }
      }
    }
  }
  .transform{
    visibility:hidden
  }
}

#controls{
  text-align: center;
  width: @width;
  margin: 0 auto;
  
  .label{
    margin-bottom: 10px;
  }
  .buttons{
    display: flex;
    flex-flow: row wrap;
    align-items: flex-start;
    justify-content: center;
    button{
      display: block;
      background: transparent;
      border: 0;
      margin: 0 5px;
      padding: 5px;
      color: @color-accent;
      position: relative;
      &:hover{
        color: #fff;
      }
      &[disabled]{
        pointer-events: none;
        color: #fff;
        &::after{
          content: "";
          position: absolute;
          left: 5px;
          right: 5px;
          bottom: -3px;
          height: 4px;
          background: @color-accent;
          border-radius: 100px
        }
      }
    }
  }
  
  .form-item{
    display: flex;
    flex-flow: row nowrap;
    align-items: center;
    .l{
      flex: 1;
    }
    input{
      flex: 1;
      background: #222;
      color: #999;
      padding: .5em;
      border: 0;
      &:focus{
        outline: 0;
        color: #fff;
      }
    }
    &:focus-within{
      background: #222;
        &::after{
          content: "";
          position: absolute;
          left: 0;
          right: 0;
          bottom: -3px;
          height: 4px;
          background: @color-accent;
          border-radius: 100px
        }
    }
  }
  
  .control{
    position: relative;
  }
  .control + .control {
    margin-top: 40px;
  }
  
  
}
            
          
!
            
              /*
Try GreenSock's MorphSVGPlugin for free.

 - Press the Fork button
 - add your own SVG, JS and HTML
 - have fun.

 Learn more about MorphSVGPlugin here: https://greensock.com/morphSVG
 MorphSVGPlugin is a bonus plugin for Shocking Green and Business Green members: https://www.greensock.com/club

*/


const paths = ["straight", "wavy", "circle"];
const pathsNames = {
  'straight': '直线',
  'wavy': '波浪线',
  'circle': '有缺口的弧线'
}

class Controls extends React.PureComponent {
  state = {
    currentPath: "straight",
    transitionDuration: 300
  };
  morphLine(to){
    this.line.classList.remove(`animation-${this.state.currentPath}`)
    gsap.to(this.line, {
      duration: this.state.transitionDuration / 1000,
      morphSVG: `#transform-${to}`
    });
    this.setState({
      currentPath: to
    })
    this.line.classList.add(`animation-${to}`)
  }
  setTransitionDuration(time){
    this.setState({
      transitionDuration: time
    })
    this.line.style.transitionDuration = `${time}ms`
  }
  componentDidMount() {
    this.selectorLine = '#transform-this-line'
    this.line = MorphSVGPlugin.convertToPath(document.querySelector(this.selectorLine))[0];
    this.line.classList.add(`animation-${this.state.currentPath}`)
  }
  render() {
    return (
      <React.Fragment>
      <div className="control control-shapes">
        <div className="label">切换</div>
        <div className="buttons">
        {paths.map(p => (
          <button type="button" disabled={p === this.state.currentPath} key={p} onClick={() => {
              this.morphLine(p)
            }}>{pathsNames[p]}</button>
        ))}
        </div>
      </div>
        <div className="control control-options">
        <div className="label">选项</div>
          <label className="form-item">
            <span className="l">动画时间 (毫秒)</span>
            <input type="number" defaultValue={this.state.transitionDuration} onChange={(evt) => this.setTransitionDuration(evt.target.value)} />
          </label>
        </div>
      </React.Fragment>
    );
  }
}

ReactDOM.render(<Controls />, document.querySelector("#controls"));

            
          
!
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