Skip to content

Conversation

codebasecodebase
Copy link
Owner

в первом задании не понял как сделать так что бы при добавлении стилей относительно текущего указателя сдвигался блок,во втором не смог понять как сделать что бы блок не вылезал за пределы родителького и не стал продолжать делать клик и т.д

@codebasecodebase
Copy link
Owner Author

во втором нужно были на каждый блок делать отдельный div? и тогда координаты не со свойства space-around высчитываются?

menu.style.top = `${event.clientY}px`;
menu.style.left = `${event.clientX}px`;
menu.classList.add("active");
if (`${event.clientX}` >= 1200) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У меня монитор 1920*1080. Поэтому меню исчезает уже при клике во второй половине экрана.
Необходимо было вычислять границу отрисовки в зависимости от размера области просмотра страницы и размеров самого меню.

menu.style.left = `${event.clientX}px`;
menu.classList.add("active");
if (`${event.clientX}` >= 1200) {
menu.style.cssText = "pading: 0";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Неверная запись свойства padding
В случае, если меню вылезает за границы страницы, его нужно лишь немного подвинуть так, чтобы оно было видно полностью на странице, а не рисовать в верхнем левом углу страницы. Для этого необходимо вычислить, на сколько пикселей меню заходит за экран и затем - отодвинуть его вверх или влево.


const menu3 = document.querySelector("#obj3");

menuArea.addEventListener( "contextmenu", event => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем вешаете 4 обработчика на один и тот же контейнер ?

const menuArea = document.querySelector("#main");
const menu1 = document.querySelector("#obj1");

menuArea.addEventListener( "contextmenu", event => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Должен обрабатываться обычный клик

width: 30px;
height: 50px;
background: purple;
position : relative;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Позиционирование должно быть абсолютным

@@ -0,0 +1,127 @@
const menuArea = document.querySelector("#main");
const menu1 = document.querySelector("#obj1");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У всех элементов одинаковая логика - можно было вешать обработчики делегированием

Y=ev.pageY;
});

function move() { //зачем аргумент ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Движение должно начинаться только при клике на элемент



window.addEventListener('load', function () { //все в один блок, т.к. вам же надо получить #obj ?
var O = document.getElementById('obj3'),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Задавайте переменным осмысленные названия

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants