如何使用JavaScript设置四个过渡属性?
在JavaScript中使用 transition属性,设置以下四个属性-transitionProperty,transitionDuration,transitionTimingFunction和transitionDelay。
示例
您可以尝试运行以下代码,以了解如何使用JavaScript设置四个过渡属性-
<!DOCTYPE html> <html> <head> <style> #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; } </style> </head> <body> <p>Hover over DIV2</p> <button onclick = "display()">Set</button> <div id = "div1">DIV1 <div id = "div2">DIV2</div> </div> <script> function display() { document.getElementById("div2").style.transition = "all 2s"; } </script> </body> </html>