How to set the four transition properties with JavaScript?

JavascriptObject Oriented ProgrammingFront End Technology

Use the transition property in JavaScript, set the following four properties − transitionProperty, transitionDuration, transitionTimingFunction, and transitionDelay.


You can try to run the following code to learn how to set the four transition properties with JavaScript −

<!DOCTYPE html>
         #div1 {
            position: relative;
            margin: 10px;
            height: 300px;
            width: 400px;
            padding: 20px;
            border: 2px solid blue;
         #div2 {
            padding: 80px;
            position: absolute;
            border: 2px solid BLUE;
            background-color: yellow;
            transform: rotateY(45deg);
         #div2:hover {
            background-color: orange;
            width: 50px;
            height: 50px;
            padding: 100px;
            border-radius: 50px;
      <p>Hover over DIV2</p>

      <button onclick = "display()">Set</button>

      <div id = "div1">DIV1
         <div id = "div2">DIV2</div>
         function display() {
            document.getElementById("div2").style.transition = "all 2s";
Published on 27-Feb-2018 08:38:42