Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

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="title"><h1>GSAP BezierPlugin</h1></div>

<div class="container">
  <img class="bee" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/234228/bee-character.svg" alt="bee">
</div>

<div class="controls">
  <select class="dropown" id="curviness">
    <option value="">Curviness Values</option>
    <option value="0">0</option>
    <option value="1">1</option>
    <option value="1.5">1.5</option>
    <option value="2">2</option>
    <option value="2.5">2.5</option>
  </select>
  
  <label for="rotate">
    <input type="checkbox" id="rotate"> autoRotate
  </label>
  
  <label for="type-thru">
    <input type="radio" id="type-thru" name="type"> Thru
  </label>
  
  <label for="type-soft">
    <input type="radio" id="type-soft" name="type"> Soft
  </label>
</div>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}

body {
  font-family: sans-serif;
}

.title {
  padding: 0.5em;
  width: 100%;
  margin: 0 auto;
  text-align: center;
  font-size: 0.8rem;
}

.container {
  max-width: 600px;
  height: 600px;
  margin: 0 auto;
  margin-bottom: 50px;
  position: relative;
  overflow: hidden;
  background: green url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/234228/flowers.svg) center center no-repeat;
  background-size: cover;
  border: 2px solid blue;
  border-radius: 25%;
  box-shadow: 0 10px 20px rgba(0, 0, 0, .5);
}

/* controls */
label, 
input[type="checkbox"],
input[type="radio"],
select {
  display: inline-block;
  margin-bottom: 1em;
}
.controls {
  width: 100%;
  max-width: 800px;
  padding: 1em;
  padding-bottom: 2em;
  margin: 0 auto;
  font-size: 1.5rem;
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
}

//svg
.bee {
  display: block;
  position: absolute;
  width: 100px;
  height: 100px;
  top: 50px;
  left: 100px;
}

              
            
!

JS

              
                //vars
const bee = document.querySelector('.bee'),
      selectCurviness = document.querySelector('#curviness'),
      checkRotate = document.querySelector('#rotate'),
      typeThru = document.querySelector('#type-thru'),
      typeSoft = document.querySelector('#type-soft'),
      points = [
        {x: 50, y: 50},
        {x: 110, y: 250},
        {x: 200, y: 400},
        {x: 300, y: 250},
        {x: 400, y: 400}  
      ];
      let curvinessVal = 0,
          rotate = false,
          bezierType = 'thru';


function start(type, curvinessVal, rotate) {
  //Initialize a timeline for the animation
  const tl = new TimelineMax();
  
  //Clear all animations and set the 
  //playhead to the beginning
  tl.progress(0).clear();
  
  //Set an initial rotation for the element (optional)
  tl.set(bee, {
    rotation: 40 
  });
  tl.to(bee, 5, {
      bezier: { //BezierPlugin properties
        curviness: curvinessVal,
        type: type,
        values: points,
        autoRotate: rotate
      },
      ease: Circ.easeInOut //Animation easing
    });
}

//Call the start()function to start the animation
start(bezierType, curvinessVal, rotate);

//Listen for the change event of the dropdown box
selectCurviness.addEventListener('change', function() {
  //If the selected index of the select box has a value
  if(this.options[this.selectedIndex].value) {
    //set the curviness value to that of the 
    //select box
    curvinessVal = this.options[this.selectedIndex].value;   
  } else {
    //Otherwise the curviness value remains unchanged
    curvinessVal = curvinessVal;
  }
  //Call the start()function to see the animation
  //using the selected value
  start(bezierType, curvinessVal, rotate); 
  console.log(curvinessVal);
});

//Listen for the change event of the autoRotate checkbox
checkRotate.addEventListener('change', function() {
  //if the checkbox is checked, set the 
  //rotate variable to true, otherwise set it to false
  if(checkRotate.checked) {
    rotate = true;
  } else {
    rotate = false;  
  }
 
  //Call the start()function to animate the element
  start(bezierType, curvinessVal, rotate); 
  console.log(curvinessVal);
});

//Listen for the change event on the radio button 
//to set the value for the soft property
typeSoft.addEventListener('change', function() {
  //When the button is selected, disable the 
  //select box for the curviness property
  //and reset it to 0
  selectCurviness.disabled = true;
  selectCurviness.selectedIndex = 0;
  selectCurviness.options[selectCurviness.selectedIndex].value = 0;
  curvinessVal = 0;
  //Call the start() function to begin the animation
  start(bezierType, curvinessVal, rotate);
  console.log(curvinessVal);
});

//Listen for the change event on the radio button 
//to set the thru value for the type property
typeThru.addEventListener('change', function() {
  //If thru is selected, enable the select box for 
  //the curviness property 
  selectCurviness.disabled = false;
  //Call the start()function to animate the element
  start(bezierType, curvinessVal, rotate);
  console.log(curvinessVal);
});

              
            
!
999px

Console