12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <!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 1s linear ;
- }
- </style>
- </head>
- <body>
- <button id="up">放大</button>
- <div id="div1"></div>
- <button id="down">缩小</button>
- <script>
- var div1 = document.getElementById('div1')
- var up = document.getElementById('up')
- var down = document.getElementById('down')
- // 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 = '500px'
- // }
- up.onclick = function(){
- div1.style.width = '500px'
- }
- down.onclick = function(){
- var timer2 = setInterval(function(){
- if(div1.offsetWidth > 300){
- div1.style.width = div1.offsetWidth - 10 + 'px'
- } else {
- clearInterval(timer2)
- }
- },10)
- }
- </script>
- </body>
- </html>
|