How do I let mouse hiding if inactive and inside a specific div ? I have the "html5gallery-box-0" div on my website, and I need the mouse to hide if the user let it idle over/inside the div after a couple of seconds. Here's the jsfiddle I'm working on.
And here's the js I'm using to hide the mouse when it's inactive.
$(function () {
var timer;
var fadeInBuffer = false;
$(document).mousemove(function () {
if (!fadeInBuffer) {
if (timer) {
console.log("clearTimer");
clearTimeout(timer);
timer = 0;
}
console.log("fadeIn");
$('html').css({
cursor: ''
});
} else {
fadeInBuffer = false;
}
timer = setTimeout(function () {
console.log("fadeout");
$('html').css({
cursor: 'none'
});
fadeInBuffer = true;
}, 500)
});
});
How do I let mouse hiding if inactive and inside a specific div ? I have the "html5gallery-box-0" div on my website, and I need the mouse to hide if the user let it idle over/inside the div after a couple of seconds. Here's the jsfiddle I'm working on.
And here's the js I'm using to hide the mouse when it's inactive.
$(function () {
var timer;
var fadeInBuffer = false;
$(document).mousemove(function () {
if (!fadeInBuffer) {
if (timer) {
console.log("clearTimer");
clearTimeout(timer);
timer = 0;
}
console.log("fadeIn");
$('html').css({
cursor: ''
});
} else {
fadeInBuffer = false;
}
timer = setTimeout(function () {
console.log("fadeout");
$('html').css({
cursor: 'none'
});
fadeInBuffer = true;
}, 500)
});
});
Share
Improve this question
edited Dec 30, 2021 at 15:03
General Grievance
5,04338 gold badges37 silver badges56 bronze badges
asked Aug 4, 2015 at 0:36
Andrea CazzolaAndrea Cazzola
1271 gold badge3 silver badges14 bronze badges
2
- So the code you currently have hides the cursor after the specified delay, but you want to know how to smoothly fade out the mouse cursor rather than just hiding it instantly? Or are you asking how to have it hide only if over that specified div? – nnnnnn Commented Aug 4, 2015 at 0:38
- My fault, I've just translated incorrectly, the problem is that with this code wherever the mouse is, it hide; and i need it to hide the cursor only if its idle inside the "html5gallery-box-0" div. – Andrea Cazzola Commented Aug 4, 2015 at 0:42
1 Answer
Reset to default 7This will work
$(function() {
var timer;
var fadeInBuffer = false;
$(document).mousemove(function() {
if (!fadeInBuffer && timer) {
console.log("clearTimer");
clearTimeout(timer);
timer = 0;
console.log("fadeIn");
$('html').css({
cursor: ''
});
} else {
$('.html5gallery-box-0').css({
cursor: 'default'
});
fadeInBuffer = false;
}
timer = setTimeout(function() {
console.log("fadeout");
$('.html5gallery-box-0').css({
cursor: 'none'
});
fadeInBuffer = true;
}, 2000)
});
$('.html5gallery-box-0').css({
cursor: 'default'
});
});
and here is the fiddle (if you want to change the idle time just do it, it's on 2 seconds now).
http://jsfiddle/eugensunic/1Lsqpm3y/4/
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744353443a4570110.html
评论列表(0条)