$(function() { function b(a) { "mousemove" == a.type && (c = +a.clientY); 50 > c && "mouseleave" == a.type && ($(document).off("mouseleave mousemove", b), alert("stop")) } var c = 100; $(document).on("mouseleave mousemove", b) });