I am trying to make a lava lamp style in jquery. It's working in codepen but not in jsfiddle or my own webpages. Can anyone help me figure out what the problem is?
Jquery code
// adds sliding underline HTML
jQuery('#menu').append('<li class="slide-line"></li>');
// 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(jQuery('#menu .slide-line'), 0.45, {
css:{
width: $this.outerWidth()+'px',
left: (offset.left-offsetBody.left)+'px',
top: (offset.top-offsetBody.top+$(this).height())+'px'
},
ease:Power2.easeInOut
});
return false;
});
jQuery('#menu > li a').first().trigger("click");
Working demo codepen
Codepen demo
Not working demo jsfiddle / normal webpages
JSFiddle demo