成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導航首頁 ? 技術教程 ? jQuery模擬物體自由落體運動(附演示與demo源碼下載)
全站頭部文字 我要出現在這里
jQuery模擬物體自由落體運動(附演示與demo源碼下載) 668 2024-03-13   

本文實例講述了jQuery模擬物體自由落體運動的方法。分享給大家供大家參考,具體如下:

運行效果截圖如下:

查看圖片

點擊此處查看在線演示效果。

完整實例代碼點擊此處本站下載。

具體代碼如下:

<!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>
 <title>自由落體</title>
 <script src="http://www.gimoo.net/t/1903/jquery-1.7.1.min.js" type="text/javascript"></script>
 <script type="text/javascript" >
  $(document).ready(function () {
  });
  var all_Height = 500;
  var a = 9.8; // 加速度
  var v = 0;
  var prev_Time = 0;
  var prev_Speed = 0;
  var prev_Height = 0;
  var speed = 0;
  // 獲取當前的高度
  var getHeight = function (obj) {
   return obj.offset().top;
  }
  // 獲取當前的速度
  var getSpeed = function (time, a) {
   return time * a;
  }
  // 向下走時獲得當前物體所走的路徑
  var getCurrentHeight = function (time) {
   return 1 / 2 * a * time * time;
  }
  // 向上走時獲得當前物體所走的路徑
  var getCurrentHeight2 = function (speed, time) {
   return speed * time - 1 / 2 * a * time * time;
  }
  // 向下跑
  function down() {
   prev_Time = 0;
   var interval = setInterval(function () {
    if (getHeight($(".obj")) < all_Height) {
     prev_Time = prev_Time + 0.1;
     var height = getCurrentHeight(prev_Time) + prev_Height;
     $(".obj").css("top", height + "px");
     $(".info").append("<div>" + height + "</div>");
    } else {
     speed = getSpeed(a, prev_Time);
     prev_Speed = speed;
     clearInterval(interval);
     up();
    }
   }, 5);
  }
  // 向上跑
  function up() {
   prev_Time = 0;
   prev_Speed -= 4; // 動能損耗
   var interval = setInterval(function () {
    if (speed > 0) {
     speed = prev_Speed - getSpeed(a, prev_Time);
     prev_Time = prev_Time + 0.1;
     var height = all_Height - getCurrentHeight2(prev_Speed, prev_Time);
     $(".obj").css("top", height + "px");
    } else {
     clearInterval(interval);
     prev_Height = $(".obj").offset().top;
     if (prev_Height < all_Height) {
      down();
     }
    }
   }, 5);
  }
  function play() {
   alert('play');
   down();
   document.getElementById("obj").onclick = null;
  }
 </script>
 <style type="text/css">
 body{ margin:0 0 0 0 ; background:#FFFFFF;}
 .title { text-align:center; color:#666666; border-bottom:2px solid gray; font-size:30px; line-height:100px; font-weight:bolder;}
 .obj { background-image:url('a.jpg'); width:50px; height:50px; position:absolute; top:0; left:0; }
 </style>
</head>
<body>
<div style="height:550px; border-bottom:2px solid gray;">
<div class="title" >自由落體大模擬<span style="font-size:12px;">(點擊圖片讓它落下)</span></div>
</div>
<div class="obj" id="obj" onclick="play();" ></div>
</body>
</html>

更多關于js運動相關內容感興趣的讀者可查看本站專題:《JavaScript運動效果與技巧匯總》

希望本文所述對大家jQuery程序設計有所幫助。



主站蜘蛛池模板: 游泳池电影| 杨英格| 苏教版二年级下册数学| 隐形变异作风问题清单及整改措施| 基于plc的毕业设计论文题目| 喜欢小红帽的原因怎么写| 大内密探灵灵狗| 李修蒙出生年月| 2025最好运头像| 秀人网门户网免费| 恐怖故事电影| 浙江卫视全天节目单| 生死瞬间演员表| 远古食人鱼| 请假单| 黑洞表面豆瓣| 天天操免费视频| 黄录象| 母亲的城堡电影在线观看| 杨玉环秘史| 河东舞曲的士高| 尤克里里谱| 罪后真相| 常景如| 陕09j01图集| 香港毛片免费看| 经典伦理电影| 白宝山电视剧26集免费观看| 法医秦明之幸存者 2018 经超| 结婚请帖怎么写| 我家来了个怪男人| 三寸天堂简谱| 夜色斗僵尸| himym| 外出韩版| 孕妇能吃杏仁吗| 乔治福尔曼| 四大美人之貂蝉香港剧| jjdd| 第一财经直播电视直播今日股市| 媚狐传|

!!!站長長期在線接!!!

網站、小程序:定制開發/二次開發/仿制開發等

各種疑難雜癥解決/定制接口/定制采集等

站長微信:lxwl520520

站長QQ:1737366103