|
@@ -0,0 +1,53 @@
|
|
|
|
|
+<!DOCTYPE html>
|
|
|
|
|
+<html lang="en">
|
|
|
|
|
+
|
|
|
|
|
+<head>
|
|
|
|
|
+ <meta charset="UTF-8">
|
|
|
|
|
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
|
+ <title>Document</title>
|
|
|
|
|
+ <style>
|
|
|
|
|
+ .box {
|
|
|
|
|
+ width: 200px;
|
|
|
|
|
+ height: 50px;
|
|
|
|
|
+ background-color: red;
|
|
|
|
|
+ }
|
|
|
|
|
+ </style>
|
|
|
|
|
+</head>
|
|
|
|
|
+
|
|
|
|
|
+<body>
|
|
|
|
|
+ <div class="box"></div>
|
|
|
|
|
+ <script>
|
|
|
|
|
+ var oBox = document.getElementsByClassName("box")[0];
|
|
|
|
|
+ // 控制递增定时器
|
|
|
|
|
+ var timer1 = null;
|
|
|
|
|
+ // 控制递减定时器
|
|
|
|
|
+ var timer2 = null;
|
|
|
|
|
+ oBox.onmouseover = function () {
|
|
|
|
|
+ clearInterval(timer2);
|
|
|
|
|
+ var _width = oBox.offsetWidth;
|
|
|
|
|
+ timer1 = setInterval(function () {
|
|
|
|
|
+ if (_width >= 600) {
|
|
|
|
|
+ clearInterval(timer1);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ _width += 10;
|
|
|
|
|
+ oBox.style.width = _width + "px";
|
|
|
|
|
+ }
|
|
|
|
|
+ }, 16);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ oBox.onmouseout = function(){
|
|
|
|
|
+ clearInterval(timer1);
|
|
|
|
|
+ var _width = oBox.offsetWidth;
|
|
|
|
|
+ timer2 = setInterval(function(){
|
|
|
|
|
+ if(_width <= 200){
|
|
|
|
|
+ clearInterval(timer2);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ _width -= 10;
|
|
|
|
|
+ oBox.style.width = _width + "px";
|
|
|
|
|
+ }
|
|
|
|
|
+ },16)
|
|
|
|
|
+ }
|
|
|
|
|
+ </script>
|
|
|
|
|
+</body>
|
|
|
|
|
+
|
|
|
|
|
+</html>
|