Вы можете выбрать и кэшировать элементы, которые должны быть исключены и использовать JQuery .index()
метод и target
свойство event
объекта.
var $blackList = $('#elem, #elem2, #elem3'),
timeout = '';
$(document).on("mousemove", function(e) {
// Removing last timout using ID returned by setTimeout(if any)
clearTimeout(timeout);
// Setting timeout using setTimeout function,
// so the handler is executed once during each specified duration
timeout = setTimeout(function() {
// event.target returnes target element of the event
// if the index of the element in jQuery collection(an array of elements) is -1
// execute the specified code
if ($blackList.index(e.target) === -1) {
// ...
}
}, 50); // change the duration according to your needs
});
«Я хочу добавить событие mousemove в тело», не делайте этого! Это будет уволено тысячу раз и в 99,99% случаев, бесполезно –