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

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

              
                <h2 style="margin-left:20px;">Lava Lamp Style Menu using GSAP - Click Event</h2>

<p style="margin-left:20px;">click a menu item to see the animated underline:</p>

<div id="box">
<ul id="menu">
  <li><a href="javascript:;">menu</a></li>
  <li><a href="javascript:;">long menu</a></li>
  <li><a href="javascript:;">even longer menu</a></li>
  <li><a href="javascript:;">short menu</a></li>
</ul>
</div>
              
            
!

CSS

              
                body {
  color:#555;
  margin:20px 0 0 0;
}

#box {
  position:relative;
  height:100px;
  margin:15px 0 0 0;
}

ul{
  margin:0;
  padding:0;
  display:block;
}

li {
  float:left;
  margin:0 0 0 10px;
  padding:10px;
  list-style-type:none; 
  font-family:Arial;
}

li a {
  display:block;
  text-decoration:none;
  font-weight:bold;
  color:#222;
}

#menu li.slide-line {
	display: block;
  padding:0;
  margin:0;
	background: none #CC0000;
	z-index: 0;
	position: absolute;
	top: 0;
	border-radius:3px;
  width: 47px; 
  height: 5px; 
  left: 0; 
  top: 0;
}
              
            
!

JS

              
                // adds sliding underline HTML
jQuery('#menu').append('<li class="slide-line"></li>');

// set initial position of slide line
TweenMax.set('#menu .slide-line', {
  css:{width: 43, x: 20, y: 30}
});

// animate slide-line on click
jQuery(document).on('click', '#menu li a', function () {
  
        var $this = jQuery(this),
            offset = $this.offset(),
            //find the offset of the wrapping div  
            offsetBody = jQuery('#box').offset();

        // GSAP animate to clicked menu item
        TweenMax.to('#menu .slide-line', 1.7, {
          css:{
            width: $this.outerWidth()+'px',
            x: (offset.left-offsetBody.left)+'px',
            y: (offset.top-offsetBody.top+$this.height())+'px',
            rotation: 0.01
          },
          ease: Elastic.easeOut.config(1,0.5)
        });

        return false;
});

jQuery('#menu > li a').first().trigger("click");
              
            
!
999px

Console