Код: Выделить всё
const myDialog = document.getElementById('notice');
const myButton = document.getElementById('button');
myButton.focus();
myButton.addEventListener('click', (e) => {
e.preventDefault();
myDialog.show();
const hideDialog = setTimeout(() => {
myDialog.close();
clearTimeout(hideDialog);
}, 5000);
});< /code>
#button:focus {
outline: 5px solid red;
}
#notice {
position: absolute;
margin: 0 auto auto;
top: 0;
transition: top 1s ease;
}
#notice:not([open]){
display: block;
top: -100%
}< /code>
Click me to show notice
Just a short noticeЕсть ли простой способ предотвратить элемент от захвата фокуса или это будет плохой практикой? Может быть, мне предпочтуется использовать для этого и не использовать элемент вообще? Я не совсем уверен, что будет лучше, особенно с точки зрения доступности. Итак, я бродил, если бы вы могли по существу изменить поведение на поведение регулярного .
Подробнее здесь: https://stackoverflow.com/questions/724 ... bing-focus
Мобильная версия