HTML DOM Style transition 属性
htmldomweb developmentfront end technology更新于 2024/5/23 23:08:17
HTML DOM Style transition 属性返回并修改 HTML 文档中 HTML 元素的 transition CSS 属性值。
语法
以下是语法 −
1. 返回 transition
object.transition
2. 修改 transition
object.transition = “value”
此处值可以为 -
| 值 | 说明 |
|---|---|
| initial | 将此属性值设置为默认值。 |
| inherit | 从其父元素继承此属性值。 |
| property duration timing-function delay | 此处,property 表示 CSS 属性的名称,例如 transition。timing-function 表示过渡效果的速度曲线。delay 表示过渡效果开始的时间。 |
让我们看一个 HTML DOM Style transition 属性的示例:
示例
<!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%;
}
.show {
font-size: 1.2rem;
margin: 1rem 0;
}
</style>
<body>
<h1>DOM Style transition Property Demo</h1>
<div class='circle'></div>
<button onclick="set()" class="btn">Set Transition</button>
<div class="show">Now, hover on the square</div>
<script>
function set() {
document.querySelector('.circle').style.transition = "all 1s";
}
</script>
</body>
</html>
输出

点击"设置过渡"按钮,然后将鼠标悬停在"红色"方块上即可查看过渡效果。

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

