|
|
@@ -0,0 +1,58 @@
|
|
|
+<!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;
|
|
|
+ margin-top: 20px;
|
|
|
+ }
|
|
|
+ </style>
|
|
|
+</head>
|
|
|
+
|
|
|
+<body>
|
|
|
+ <div class="box"></div>
|
|
|
+ <div class="box"></div>
|
|
|
+ <div class="box"></div>
|
|
|
+ <script>
|
|
|
+ var aBox = document.getElementsByClassName("box");
|
|
|
+ var timer1 = null;
|
|
|
+ for (var i = 0; i < aBox.length; i++) {
|
|
|
+ aBox[i].index = i;
|
|
|
+ aBox[i].onmouseover = function () {
|
|
|
+ var _index = this.index;
|
|
|
+ clearInterval(aBox[_index].timer2)
|
|
|
+ aBox[_index].timer1 = setInterval(function () {
|
|
|
+ var _width = aBox[_index].offsetWidth;
|
|
|
+ if (_width >= 600) {
|
|
|
+ clearInterval(aBox[_index].timer1)
|
|
|
+ } else {
|
|
|
+ _width += 10;
|
|
|
+ aBox[_index].style.width = _width + "px";
|
|
|
+ }
|
|
|
+ }, 16)
|
|
|
+ }
|
|
|
+
|
|
|
+ aBox[i].onmouseout = function () {
|
|
|
+ var _index = this.index;
|
|
|
+ clearInterval(aBox[_index].timer1)
|
|
|
+ aBox[_index].timer2 = setInterval(function () {
|
|
|
+ var _width = aBox[_index].offsetWidth;
|
|
|
+ if (_width <= 200) {
|
|
|
+ clearInterval(aBox[_index].timer2)
|
|
|
+ } else {
|
|
|
+ _width -= 10;
|
|
|
+ aBox[_index].style.width = _width + "px";
|
|
|
+ }
|
|
|
+ }, 16)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ </script>
|
|
|
+</body>
|
|
|
+
|
|
|
+</html>
|