|
@@ -0,0 +1,59 @@
|
|
|
+<!DOCTYPE html>
|
|
|
+<html lang="en">
|
|
|
+
|
|
|
+<head>
|
|
|
+ <meta charset="UTF-8">
|
|
|
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
|
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
+ <title>Document</title>
|
|
|
+ <style>
|
|
|
+ * {
|
|
|
+ margin: 0;
|
|
|
+ padding: 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ #div1 {
|
|
|
+ width: 200px;
|
|
|
+ height: 200px;
|
|
|
+ background: red;
|
|
|
+ transition: width 2s linear;
|
|
|
+ }
|
|
|
+ </style>
|
|
|
+</head>
|
|
|
+
|
|
|
+<body>
|
|
|
+ <button id="up">放大</button>
|
|
|
+ <div id="div1"></div>
|
|
|
+ <button id="down">缩小</button>
|
|
|
+ <script>
|
|
|
+ var up = document.getElementById('up')
|
|
|
+ var down = document.getElementById('down')
|
|
|
+ var div1 = document.getElementById('div1')
|
|
|
+
|
|
|
+ // up.onclick = function () {
|
|
|
+ // var timer = setInterval(function () {
|
|
|
+ // if (div1.offsetWidth < 500) {
|
|
|
+ // div1.style.width = div1.offsetWidth + 10 + 'px'
|
|
|
+ // } else {
|
|
|
+ // clearInterval(timer)
|
|
|
+ // }
|
|
|
+ // }, 10);
|
|
|
+ // // div1.style.width = 500 + 'px'
|
|
|
+ // }
|
|
|
+ up.onclick = function () {
|
|
|
+ div1.style.width = 500 + 'px'
|
|
|
+ }
|
|
|
+
|
|
|
+ down.onclick = function () {
|
|
|
+ var timer1 = setInterval(function () {
|
|
|
+ if (div1.offsetWidth > 0) {
|
|
|
+ div1.style.width = div1.offsetWidth - 10 + 'px'
|
|
|
+ } else {
|
|
|
+ clearInterval(timer1)
|
|
|
+ }
|
|
|
+ }, 10)
|
|
|
+ }
|
|
|
+ </script>
|
|
|
+</body>
|
|
|
+
|
|
|
+</html>
|