Я беженец Flex/Actionscript и пытаюсь пробиться в JS/HTML5/CSS3. Некоторые вещи имеют непосредственный смысл, но тогда есть и другие, которых просто нет.Что это за "document.all" делает?
Я смотрю на эту JSfiddle "Pure Javascript Draggable" и я не понимая эту линию (или, вернее, я понимаю, что он делает, но не так, как он это делает)
x_pos = document.all ? window.event.clientX : e.pageX;
Я посмотрел «документ. все "и, похоже, это сокращение от Element.querySelectorAll()
без аргументов?
Возвращает неживые NodeList всех элементов происходят от элемента , на котором она применяла соответствует указанной группе CSS селекторов.
- Это правильно? Итак, параметр «all» означает, что он возвращает все в DOM?
- Что означает «неживой» NodeList? «Неживой»?
- И фактическая строка ... тестирование, если window.event.clientX или e.pageX не является нулевым?
Основные вещи, но сбивает с толку.
var selected = null, // Object of the element to be moved
x_pos = 0, y_pos = 0, // Stores x & y coordinates of the mouse pointer
x_elem = 0, y_elem = 0; // Stores top, left values (edge) of the element
// Will be called when user starts dragging an element
function _drag_init(elem) {
// Store the object of the element which needs to be moved
selected = elem;
x_elem = x_pos - selected.offsetLeft;
y_elem = y_pos - selected.offsetTop;
}
// Will be called when user dragging an element
function _move_elem(e) {
x_pos = document.all ? window.event.clientX : e.pageX;
y_pos = document.all ? window.event.clientY : e.pageY;
if (selected !== null) {
selected.style.left = (x_pos - x_elem) + 'px';
selected.style.top = (y_pos - y_elem) + 'px';
}
}
// Destroy the object when we are done
function _destroy() {
selected = null;
}
// Bind the functions...
document.getElementById('draggable-element').onmousedown = function() {
_drag_init(this);
return false;
};
document.onmousemove = _move_elem;
document.onmouseup = _destroy;
Нет, 'document.all' - старая вещь Microsoft IE. В основном это (плохой) способ обнаружить, что код работает в Internet Explorer. – Pointy