Hi I'm using a jQuery custom underline plugin (below) the code is relatively simple, currently the underline appears with a mouseover function and disappears with mouseout, also only one instance of the underline can exist on he webpage at any one time. I would like to adapt the code so that the underline is permanent with regardless of mouse movement and several instances can exist on one page but am struggling to make it work. Here is the current code:
<script language="JavaScript" type="text/javascript">
$(document).ready(function() {
$('.underline a').underline({
width: 4, //default: 1
distance: -1, //default: 0
color: '#66FFB2', //default: #000
durationOn: 350, //default: 250
durationOff: 350, //default: 250
extend: 2, //default: 2,
linkOn: 'mouseover', //default: 'mouseover'
linkOff: 'mouseout' //default: 'mouseout'
});
});
</script>
(function($){
$.fn.underline = function(options) {
var defaults = {
width: 1,
distance: 0,
color: '#000',
durationOn: 250,
durationOff: 250,
extend: 2,
linkOn: 'mouseover',
linkOff: 'mouseout'
};
var options = $.extend(defaults, options);
return this.each(function() {
obj = $(this);
//Mouse Events
var linkOn = options.linkOn;
var linkOff = options.linkOff;
obj.bind(linkOn, function() {
$('#underlineLine').remove();
var position = $(this).offset();
var top = position.top;
var left = position.left;
var objWidth = $(this).width();
var objHeight = $(this).height();
$('body').append('<div id="underlineLine"></div>');
$('#underlineLine').css({'position' :'absolute',
'display' :'none',
'height' : options.width+'px',
'background-color': options.color,});
$('#underlineLine').css({'left' : left-options.extend,
'top' : top+objHeight+options.distance,
'width': objWidth+options.extend*2 })
.fadeIn(options.durationOn);
});
obj.bind(/*linkOff,*/ function() {
$('#underlineLine').fadeOut(options.durationOff);
});
});
};
})(jQuery);
<div class="underline"><a href="#">LINK</a></div>
Thanks!