<button id="run">click me</button>
<div id="block"></div>
.fade-effect.-show {
animation: fade 0.5s ease;
}
@keyframes fade {
from { opacity: 0; }
to { opacity: 1 }
}
const textArr = [ 'OH', 'MY', 'GLOB' ]
const divEl = document.querySelector('#block')
const changeDelay = 2000
const fadeOutDelay = 1000
document.querySelector('#run').addEventListener('click', () => {
textArr.map((txt, idx) => {
setTimeout(() => {
divEl.className = 'fade-effect -show'
divEl.innerHTML = txt
setTimeout(() => {
divEl.className = ''
}, !idx ? fadeOutDelay : idx * fadeOutDelay)
}, idx * changeDelay)
})
})
<a id="fakelink" data-href="http://google.com">click</a>
document.querySelector('#fakelink').addEventListener('click', function() {
var link = this.getAttribute('data-href')
this.setAttribute('href', link)
})
$('#yourform').on('submit', function(e) {
e.preventDefault(); // для того, чтобы выключить стандартное поведение для формы
// your ajax code ...
})
var obj = JSON.parse(yourResponseTextFromServer)
document.querySelector('#somediv').innerHTML = obj.data.text
.overlay {
background: rgba(0, 0, 0, 0.5)
}
body {
position: relative;
}
body::after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%; height: 100%;
background: rgba(0, 0, 0, 0.5)
}