简体   繁体   中英

How to disabled javascript when mouse out div?

How to disabled javascript when mouse out div ?

This is my code onmousemove to change div id left width, but why javascript still work, when i onmouseout id container how to disabled javascript when i onmouseout out id container

i tried

    container.on('mouseout', function (e) {
        isResizing = false;
    });

but not work , how can i do that ?

https://jsfiddle.net/ksfqgv0p/2/

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);
    });
});
var isResizing = false;
$(function () {
   var container = $('#container'),
        left = $('#left'),
        handle = $('#handle');

    left.on('mousemove', function (e) {
        isResizing = true;
    });

    left.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);
    });
});

DEMO FIDDLE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM