I am trying to create a menu that will be visible when the mouse is next to the left viewport (say, up to 100 pixels on the left, otherwise in the "Show" menu). It should look a bit like the Windows 8 firewall.
I already have the following, but actually it does not work.
var mouse_position;
$(document).mousemove(function (mouse_pointer) {
mouse_position = mouse_pointer.clientX;
if (mouse_position <= 100 && !$("#cms_bar").is(":visible")) {
$('#cms_bar').show().animate({
width: '100px'
}), 500;
console.log('menu shown');
} else if (mouse_position > 100 && $("#cms_bar").is(":visible")) {
$('#cms_bar').animate({
width: '0px'
}, 500, function () {
$(this).hide();
console.log('menu hidden');
});
}
});
It’s clear that I am doing something wrong.
EDIT
var mouse_position;
$(document).mousemove(function(mouse_pointer) {
mouse_position = mouse_pointer.clientX;
if (mouse_position <= 100 && !$("#cms_bar").is(":visible")) {
$('#cms_bar').stop().show().animate({width: '100px'}), 300;
console.log('menu shown');
}
else if (mouse_position > 100 && $("#cms_bar").is(":visible")) {
$('#cms_bar').stop().animate({
width: '0px'
}, 300, function() {
$(this).css("display","none")
console.log('menu hidden');
});
}
});
It seems that editing is a bit more, the problem was that when you hide the menu, the animation should be completed. If not, and you where again with the mouse <100 then it got stuck and nothing was shown.
Maybe someone has a smoother solution?
source
share