The transition property does not handle discrete values (discontinuous, consist of individual values, for example, block , inline , inline-block ...), but only analog ones (for example, numbers, colors).
For example, let's make opacity: 0 , and when you click it will change it to opacity: 1 . Add transition: opacity 1s ease-in-out , but nothing works again, why? The answer is not so obvious, all because of the JavaScript processing engine, or rather its event-loop , it processes and changes the values of css properties, but does not allow time for its rendering by the browser. You can solve this by wrapping our property change in setTimeout - setTimeout(() => buttons[i].style.opacity = 1, 0) . SetTimeout with zero value, sense? And the point is that between these functions there will be a transfer of control to the browser and it will draw our animation.
PS dots.style.display = 'none' , you need to assign it to the parent.
PPS You can find out more about the event-loop here.
var buttons = document.querySelectorAll('ul li'); for (var i = 3; i < buttons.length - 2; i++) { buttons[i].style.display = "none"; buttons[i].style.opacity = 0; } var dots = document.querySelector('ul li span'); dots.onclick = function () { for (let i = 0; i < buttons.length; i++) { buttons[i].style.display = "inline"; setTimeout(() => buttons[i].style.opacity = 1, 0) } dots.parentElement.style.display = 'none'; }
ul > li { display: inline; padding: 10px; background: #c7c7c7; transition: opacity 1s ease-in-out }
<ul> <li><a href="">Следующая</a></li> <li><a href="">1</a></li> <li style="cursor: pointer"><span>...</span></li> <li><a href="">2</a></li> <li><a href="">3</a></li> <li><a href="">4</a></li> <li><a href="">6</a></li> <li><a href="">7</a></li> <li><a href="">Предыдущая</a></li> </ul>