记住,大部分动画都可以通过添加和移除class来实现的!!!
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<style type="text/css">
div {
width: 100px;
height: 2px;
background: #0000FF;
transition: width 1s linear;
}
.animate {
width: 1000px;
}
</style>
</head>
<body>
<div></div>
<br /><br />
<button>click</button>
<script>
document.querySelector('button').addEventListener('click', function() {
document.querySelector('div').classList.add('animate');
})
</script>
</body>
</html>