码迷,mamicode.com
首页 > Web开发 > 详细

简单的JS运动封装实例---侧栏分享到

时间:2014-05-30 01:35:06      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   blog   code   java   

bubuko.com,布布扣
 1 <!DOCTYPE HTML>
 2 <html>
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 5 <title>无标题文档</title>
 6 <style>
 7 #div1 {width: 100px; height: 200px; background: red; position: absolute; left: -100px; top: 100px;}
 8 #div2 {width: 30px; height: 60px; background: black; position: absolute; right: -30px; top: 70px; color: white; text-align: center;}
 9 </style>
10 <script>
11 window.onload = function() {
12     
13     var oDiv1 = document.getElementById(div1);
14     var oDiv2 = document.getElementById(div2);
15     var iTimer = null;
16     
17     oDiv1.onmouseover = function() {
18         startMove(0, 10);
19     }
20     
21     oDiv1.onmouseout = function() {
22         startMove(-100, -10);
23     }
24     
25     function startMove(iTarget, iSpeed) {
26         clearInterval(iTimer);
27             
28         iTimer = setInterval(function() {
29             
30             if (oDiv1.offsetLeft == iTarget) {
31                 clearInterval(iTimer);
32             } else {
33                 oDiv1.style.left = oDiv1.offsetLeft + iSpeed + px;
34             }
35             
36         }, 30);
37     }
38     
39 }
40 </script>
41 </head>
42 
43 <body>
44     <div id="div1">
45         <div id="div2">分享到</div>
46     </div>
47 </body>
48 </html>
bubuko.com,布布扣

 

简单的JS运动封装实例---侧栏分享到,布布扣,bubuko.com

简单的JS运动封装实例---侧栏分享到

标签:c   style   class   blog   code   java   

原文地址:http://www.cnblogs.com/trtst/p/3757922.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!