Is it possible to disable JavaScript when moving the mouse out of a div?
I have implemented code using onmousemove
to adjust the width of the left
div ID. However, I noticed that JavaScript continues to work even when I move the mouse out of the container
ID. How can I prevent JavaScript from executing when I move the mouse out of the container
ID?
I attempted the following:
container.on('mouseout', function (e) {
isResizing = false;
});
Unfortunately, this solution did not work. Is there another way to achieve this functionality?
var isResizing = false;
$(function () {
var container = $('#container'),
left = $('#left'),
handle = $('#handle');
container.on('mousemove', function (e) {
isResizing = true;
});
container.on('mouseout', function (e) {
isResizing = false;
});
$(document).on('mousemove', function (e) {
if (!isResizing)
return;
left.css('width', e.clientX - container.offset().left);
handle.css('margin-left', e.clientX - container.offset().left);
});
});