html - Jquery IF hover (execute) ELSE fadein/out -
i'm trying add if statement script. script supposed fade out when there no mouse movement & fade in when there is. i'm trying make stays faded in regardless of mouse movement if hover on div running script.
http://jsfiddle.net/2kyaj/1098/
$(function () { var timer; var fadeinbuffer = false; $(document).mousemove(function () { if (('.fade-object').mouseover) { $('.fade-object').fadein(); } else { if (!fadeinbuffer) { if (timer) { console.log("cleartimer"); cleartimeout(timer); timer = 0; } console.log("fadein"); $('.fade-object').fadein(); $('html').css({ cursor: '' }); } else { fadeinbuffer = false; } timer = settimeout(function () { console.log("fadeout"); $('.fade-object').fadeout() $('html').css({ cursor: 'none' }); fadeinbuffer = true; }, 1000) } }); });
this not whole solution, may help.
set var
tells if div
hovered or not:
var hovered = false; $('div').on('mouseenter', function () { hovered = true; }); $('div').on('mouseleave', function () { hovered = false; });
turn on , off mousemove
event:
$(document).on('mousemove', function () {...}); $(document).off('mousemove', function () {...});
so can example switching mousemove
event when hovering/leaving div
or can check if (hovered == true) {...}
. choice yours :)
Comments
Post a Comment