0

This is my code in js:

        window.onload = function(){
            var bsDiv = document.getElementById("box");
            var x, y;
// On mousemove use event.clientX and event.clientY to set the location of the div to the location of the cursor:
            window.addEventListener('mousemove', function(event){
                x = event.clientX;
                y = event.clientY;                    
                if ( typeof x !== 'undefined' ){
                    bsDiv.style.left = x + "px";
                    bsDiv.style.top = y + "px";
                }
            }, false);
        }
    </script>

i want to add a function that if the cursor is off screen (or at position null?) it makes the element invisible and then make it re-visible on the cursors re entry

1 Answers1

0

document.onmouseout is triggered when the mouse leaves the screen.

so do something like

function invisible(div){
    div.style.visibility = 'hidden';
}
document.addEventListener(onmouseout, invisible(divName), true);
rassar
  • 5,412
  • 3
  • 25
  • 41
  • Did you try it? It does not work. It also bubbles so all `mouseout` will make it think it is outside the window. – doug65536 Oct 18 '16 at 22:25