Есть объект, ширина которого равна заданному в инпуте значению и меняется в зависимости от значения:
document.querySelector('#input-width').addEventListener('input', width => {
if (width.target.value < 280 ) {
document.querySelector('#square').style.width = width.target.value + 'px';
} else if (width.target.value < 500) {
document.querySelector('#square').style.width = width.target.value / 2 + 'px';
} else {
document.querySelector('#square').style.width = width.target.value / 10 + 'px';
}
})
Есть объект, позиционирование которого задается значением из другого инпута относительно левого края и меняется в зависимости от размера первого объекта:
document.querySelector('#input-otverstie-x').addEventListener('input', kevt => {
if (width.target.value < 280 ) {
document.querySelector('#show-otverstie').style.left = kevt.target.value + 'px';
} else if (width.target.value < 500) {
document.querySelector('#show-otverstie').style.left = kevt.target.value / 2 + 'px';
} else {
document.querySelector('#show-otverstie').style.left = kevt.target.value / 10 + 'px';
}
})
Но проблема в том, что в такой конструкции значение переменной width не передается во вторую функцию и условие не выполняется. Как можно правильно передать значение переменной?
let width = document.getElementById('square').offsetWidth
width
пихать в условия