Change Div Color On Mouseenter During Timeout - Jquery Function
Right now I have this code: $('.a').mouseenter(function(){ var $this = $(this); clearTimeout($this.data('timerMouseleave')); $this.css('border', 'solid 1px #444444') }
Solution 1:
Try
$('.a').mouseenter(function(){
var $this = $(this);
clearTimeout($this.data('timerMouseleave'));
if($this.hasClass('hide-timer')){
$this.css('border', 'solid 1px red')
} else {
$this.css('border', 'solid 1px #444444')
}
}).mouseleave(function(){
var $this = $(this);
var timer = setTimeout($.proxy(function(){
$this.css('border', 'solid 1px #dddddd').removeClass('hide-timer')
}, this), 1000)
$this.data('timerMouseleave', timer).addClass('hide-timer')
}).click(function(){
var $this = $(this);
$this.css('border', 'solid 1px black')
$this.off('mouseenter mouseleave');
})
Demo: Fiddle
Post a Comment for "Change Div Color On Mouseenter During Timeout - Jquery Function"