Skip to content

Instantly share code, notes, and snippets.

@raddevon
Created May 16, 2013 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raddevon/5591455 to your computer and use it in GitHub Desktop.
Save raddevon/5591455 to your computer and use it in GitHub Desktop.
A jQuery plugin that slides out a div the color of the trigger element's left border.
(function( $ ){
$.fn.colorSlide = function() {
var trigger = $(this);
var elWidth = trigger.outerWidth();
var elHeight = trigger.outerHeight();
var elPosition = trigger.offset();
var elColor = trigger.css('border-left-color');
trigger.find('a').css({
'position': 'relative',
'z-index': 51
});
var colorSlider = $('<div class="color-slider"></div>');
colorSlider.css({
'background': elColor,
'width': 0,
'position': 'absolute',
'z-index': 50
}).offset(elPosition).appendTo(trigger);
trigger.on('mouseenter mouseleave', function(e) {
if (e.type === 'mouseenter') {
colorSlider.css({ 'width': elWidth, 'height': elHeight });
} else if (e.type === 'mouseleave') {
colorSlider.css('width', 0);
}
});
};
})( jQuery );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment