hyljava

          js 網頁中文本塊碰壁反彈特效,有控制按鈕

          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml">
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
          <title>碰壁反彈</title>
          <style>
          #text {width:500px;height:300px;border:10px red solid;margin:0 auto;position:relative;}
          #div1 {width:50px;height:50px;border:5px yellow solid;position:absolute;}
          </style>
          </head>
          <body>
          <div id="text">
          <div id="div1"></div>
          </div>
          <input type="button" value="開始"/>
          <input type="button" value="變大"/>
          <input type="button" value="變小"/>
          <input type="button" value="停止"/>
          </body>
          <script type="text/javascript">
          var text = document.getElementById("text");
          var div1 = document.getElementById("div1");
          var a = div1.offsetTop;
          var b = div1.offsetLeft;
          var id = true;
          var id2 = true;
          var ss=null;
          var qw = 50;
          var ge = true;
          var gg = true;
          function pbft(){
          var width = text.clientWidth;
          var height = text.clientHeight;
          var width2 = div1.offsetWidth;
          var height2 = div1.offsetHeight;
          var width3 = width - width2;
          var height3 = height - height2;
          if(id){
          if(b<width3){
          b++;
          this.div1.style.left = b + "px";
          }else{
          id = false;
          }
          }else{
          if(b>0){
          b--;
          this.div1.style.left = b + "px";
          }else{
          id=true;
          }
          }
          if(id2){
          if(a<height3){
          a++;
          this.div1.style.top = a + "px";
          }else{
          id2 = false;
          }
          }else{
          if(a>0){
          a--;
          this.div1.style.top = a + "px";
          }else{
          id2=true;
          }
          }
          }
          function dian(){
          var da = document.getElementsByTagName("input")[1];
          var xiao = document.getElementsByTagName("input")[2];
          var stop = document.getElementsByTagName("input")[3];
          var kais = document.getElementsByTagName("input")[0];
          ade(da,'click',function(){bd()});
          ade(xiao,'click',function(){bx()});
          ade(stop,'click',function(){tz()});
          ade(kais,'click',function(){ks()});
          }
          // Resources from http://www.veryhuo.com/down
          function ade(a,b,c){
          if (a.addEventListener)
          {
          a.addEventListener(b,c,false)
          }else{
          a["on"+b] = c ;
          }
          }
          function ks(){
          if (ss)
          {
          clearInterval(ss);
          }
          ss = setInterval(pbft,10);
          }
          function bd(){
          if (qw<=200)
          {
          qw++;
          this.div1.style.width = qw + "px";
          this.div1.style.height = qw + "px";
          clearTimeout(ge);
          gg = setTimeout(bd,20)
          }
          }
          function bx(){
          if (qw>50)
          {
          qw--;
          this.div1.style.width = qw + "px";
          this.div1.style.height = qw + "px";
          clearTimeout(gg);
          ge = setTimeout(bx,20)
          }
          }
          function tz(){
          clearInterval(ss);
          clearTimeout(gg);
          clearTimeout(ge);
          }
          dian();
          </script>
          </html>
          <!-- Liehuo Button BEGIN -->
          <script type='text/javascript' src='http://www.veryhuo.com/Res/share/jscss/Liehuo_r.js?btn=r3.gif' charset=utf-8></script>
          <!-- Liehuo Button END --><br /><center>如不能顯示效果,請按Ctrl+F5刷新本頁,更多網頁代碼:<a target='_blank'>http://www.veryhuo.com/</a></center>
          文章源自:烈火網,原文:http://www.veryhuo.com/a/view/29262.html

          posted on 2012-05-22 08:24 何云隆 閱讀(363) 評論(0)  編輯  收藏 所屬分類: JS

          主站蜘蛛池模板: 兴化市| 怀宁县| 古田县| 寿阳县| 韶山市| 石嘴山市| 万州区| 沁源县| 太谷县| 彭泽县| 济阳县| 通江县| 黄平县| 全椒县| 焉耆| 姚安县| 阳曲县| 鹿邑县| 抚松县| 垫江县| 津南区| 山阳县| 方正县| 谢通门县| 即墨市| 丹江口市| 屏东县| 阿荣旗| 高邮市| 遂平县| 钟山县| 叙永县| 沅陵县| 绵阳市| 内黄县| 龙游县| 安丘市| 开鲁县| 阆中市| 蛟河市| 恭城|