HTML DOM Style transitionProperty 属性

htmldomweb developmentfront end technology更新于 2024/5/23 22:04:17

HTML DOM Style transitionProperty 属性返回并修改 HTML 文档中过渡效果元素的 CSS 属性名称。

语法

以下是语法 −

1. 返回 transitionProperty

object.transitionProperty

2. 修改 transitionProperty

object.transitionProperty = “value”

此处值可以为 -

值说明
initial将此属性值设置为默认值。
inherit从其父元素继承此属性值。
all为所有属性设置过渡效果。
property表示 CSS 属性列表。
none不选择任何属性。

让我们看一个 HTML DOM Style transitionProperty 的示例属性:

示例

<!DOCTYPE html>
<html>
<style>
   body {
      color: #000;
      height: 100vh;
   }
   .btn {
      background: #db133a;
      border: none;
      height: 2rem;
      border-radius: 2px;
      width: 40%;
      display: block;
      color: #fff;
      outline: none;
      cursor: pointer;
      margin: 1rem 0;
   }
   .circle {
      height: 100px;
      width: 100px;
      background-color: #db133a;
   }
   .circle:hover {
      height: 200px;
      width: 200px;
      border-radius: 50%;
      transition: all 1s;
   }
   .show {
      font-size: 1.2rem;
      margin: 1rem 0;
   }
</style>
<body>
<h1>DOM Style transitionProperty Property Demo</h1>
<div class='circle'></div>
<button onclick="set()" class="btn">Change TransitionProperty</button>
<div class="show">Now, hover on the square</div>
<script>
   function set() {
      document.querySelector('.circle').style.transitionProperty = "border-radius";
   }
</script>
</body>
</html>

输出

点击"更改 TransitionProperty"按钮,然后将鼠标悬停在"红色"方块上以查看 transitionProperty 效果。


相关文章


有用资源