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

Auto Save

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

              
                h1 Меню с плавающей полоской в стиле Lava-Lamp
// измените main-nav на любой класс, не забудьте при этом изменить main-nav в стилях и скриптах
- var c = 'main-nav'

nav(class=c)
	- for (var i = 1; i <= 3; i++)
		if i === 2
			a(href="#", class=c + '__item-parent')
				em(class=c + '__item' + ' ' + c + '__item--on')= 'Item - ' + i
		else if i === 3
			a(href="#", class=c + '__item-parent')
				em(class=c + '__item')= 'Long item - ' + i
		else
			a(href="#", class=c + '__item-parent')
				em(class=c + '__item')= 'Item - ' + i
              
            
!

CSS

              
                @import 'nib'

green = #85C447
blue = #4AC5FF
red = #F14B50

.main-nav
	position relative
	clearfix()
	&, *
		display block
		margin 0
		padding 0
		box-sizing border-box
		font-weight normal
		font-style normal
	&__item-parent
		float left
		padding 10px 20px
	&__lodash
		position absolute
		bottom 0
		height 5px
	&__lodash--on
		background blue
		z-index 99
	&__lodash--hover
		background red
		z-index 9
		
	
		
		
              
            
!

JS

              
                (function($){
 	jQuery.fn.lavaLampLodash = function(opt){
		opt = $.extend({
			speed: 500, // скорость анимации
			prefix: 'main-nav', // префикс для классов внутри меню
			returnStarting: true // если true, то плавающая полоска при убирании с меню будет улетать к активному пункту
		}, opt);

		var make = function() {
			var $this = $(this);
			var itemParent = $this.find('.' + opt.prefix + '__item-parent');
			var item = $this.find('.' + opt.prefix + '__item');
			var onItem = $this.find('.' + opt.prefix + '__item--on');
			var onLodash = $('<i/>', {
				class: opt.prefix + '__lodash ' + opt.prefix + '__lodash--on'
			});
			var hoverLodash = $('<i/>', {
				class: opt.prefix + '__lodash ' + opt.prefix + '__lodash--hover'
			});
			var setCssLodash = function(el, stepfather) {
				el.css({
					width: stepfather.width(),
					left: stepfather.position().left
				});
			};
			var setAnimateLodash = function(el, stepfather) {
				el.stop().animate({
					width: stepfather.width(),
					left: stepfather.position().left
				}, opt.speed);
			};
			
			$this.append(onLodash, hoverLodash);
			setCssLodash(onLodash, onItem);
			setCssLodash(hoverLodash, onItem);
			
			itemParent.hover(
				function() {
					var $el = $(this).find('.' + opt.prefix + '__item');
					setAnimateLodash(hoverLodash, $el);
				}, function() {
					var $el = opt.returnStarting ? onItem : $(this).find('.' + opt.prefix + '__item');
					setAnimateLodash(hoverLodash, $el);
				}
			);
		};

		return this.each(make); 
	};
})(jQuery);

$('.main-nav').lavaLampLodash({
	speed: 400,
	returnStarting: true,
	prefix: 'main-nav'
});
              
            
!
999px

Console