Подключить скрипт к сайту на php
- Есть скрипт, который скрывает уведомление через 5 секунд. Его нужно подключить к модальному окну, где выводятся эти уведомления.
document.addEventListener('DOMContentLoaded', function() {
let a = document.querySelector('.link-alert'),
div = document.querySelector('.alert.alert-success');
div.hide(0);
a.onclick = function() {
div.show(300);
setTimeout(function() { div.hide(300); }, 5000);
};
});
HTMLElement.prototype.show = function(time) {
this.style.opacity = 1;
this.style.visibility = 'visible';
this.style.transition = time + 'ms all ease';
};
HTMLElement.prototype.hide = function(time) {
this.style.opacity = 0;
this.style.visibility = 'hidden';
this.style.transition = time + 'ms all ease';
};
</script>
<a href="#" class="link-alert">alert show</a>
<div class="alert alert-success">
Успешно
</div>
<style>
a.link-alert { font-family: sans-serif; }
div.alert.alert-success { font-family: sans-serif; padding: 1em; color: #3c763d; background-color: #dff0d8; border: 1px solid #d6e9c6; }
</style>