jQuery模擬物體自由落體運(yùn)動(dòng)(附演示與demo源碼下載)
本文實(shí)例講述了jQuery模擬物體自由落體運(yùn)動(dòng)的方法。分享給大家供大家參考,具體如下:
運(yùn)行效果截圖如下:
點(diǎn)擊此處查看在線演示效果。
完整實(shí)例代碼點(diǎn)擊此處本站下載。
具體代碼如下:
<!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="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; // 獲取當(dāng)前的高度 var getHeight = function (obj) { return obj.offset().top; } // 獲取當(dāng)前的速度 var getSpeed = function (time, a) { return time * a; } // 向下走時(shí)獲得當(dāng)前物體所走的路徑 var getCurrentHeight = function (time) { return 1 / 2 * a * time * time; } // 向上走時(shí)獲得當(dāng)前物體所走的路徑 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; // 動(dòng)能損耗 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;">(點(diǎn)擊圖片讓它落下)</span></div> </div> <div class="obj" id="obj" onclick="play();" ></div> </body> </html>
更多關(guān)于js運(yùn)動(dòng)相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《JavaScript運(yùn)動(dòng)效果與技巧匯總》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
- jquery實(shí)現(xiàn)隱藏在左側(cè)的彈性彈出菜單效果
- jQuery彈性滑動(dòng)導(dǎo)航菜單實(shí)現(xiàn)思路及代碼
- Jquery實(shí)現(xiàn)彈性滑塊滑動(dòng)選擇數(shù)值插件
- jQuery實(shí)現(xiàn)背景彈性滾動(dòng)的導(dǎo)航效果
- 基于jQuery的煙花效果(運(yùn)動(dòng)相關(guān))點(diǎn)擊屏幕出煙花
- jQuery實(shí)現(xiàn)的分子運(yùn)動(dòng)小球碰撞效果
- jQuery實(shí)現(xiàn)跟隨鼠標(biāo)運(yùn)動(dòng)圖層效果的方法
- jQuery拋物線運(yùn)動(dòng)實(shí)現(xiàn)方法(附完整demo源碼下載)
- jQuery實(shí)現(xiàn)橫向帶緩沖的水平運(yùn)動(dòng)效果(附demo源碼下載)
- jquery模擬實(shí)現(xiàn)鼠標(biāo)指針停止運(yùn)動(dòng)事件
- jquery animate動(dòng)畫持續(xù)運(yùn)動(dòng)的實(shí)例
- jQuery插件實(shí)現(xiàn)彈性運(yùn)動(dòng)完整示例
相關(guān)文章
jquery的父、子、兄弟節(jié)點(diǎn)查找,節(jié)點(diǎn)的子節(jié)點(diǎn)循環(huán)方法
下面小編就為大家?guī)硪黄猨query的父、子、兄弟節(jié)點(diǎn)查找,節(jié)點(diǎn)的子節(jié)點(diǎn)循環(huán)方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-12-12jQuery EasyUI之DataGrid使用實(shí)例詳解
這篇文章主要介紹了jQuery EasyUI之DataGrid使用實(shí)例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-01-01jQuery中對(duì)節(jié)點(diǎn)進(jìn)行操作的相關(guān)介紹
本篇文章小編將為大家介紹,在jQuery中對(duì)節(jié)點(diǎn)進(jìn)行操作的解決辦法,有需要的朋友可以參考一下2013-04-04jQuery簡(jiǎn)單實(shí)現(xiàn)網(wǎng)頁(yè)選項(xiàng)卡特效
本文給大家分享一段基于jQuery簡(jiǎn)單實(shí)現(xiàn)的網(wǎng)頁(yè)選項(xiàng)卡代碼,非常簡(jiǎn)單實(shí)用,這里推薦給小伙伴們。2014-11-11基于jQuery實(shí)現(xiàn)的無(wú)刷新表格分頁(yè)實(shí)例
這篇文章主要介紹了基于jQuery實(shí)現(xiàn)的無(wú)刷新表格分頁(yè)方法,結(jié)合完整實(shí)例形式較為詳細(xì)的分析了jQuery實(shí)現(xiàn)無(wú)刷新表格分頁(yè)的具體步驟與相關(guān)實(shí)現(xiàn)代碼,需要的朋友可以參考下2016-02-02jQuery元素屬性操作實(shí)例(設(shè)置、獲取及刪除元素屬性)
這篇文章主要介紹了jQuery元素屬性操作的方法,結(jié)合實(shí)例形式分析了jQuery針對(duì)頁(yè)面元素的設(shè)置、獲取及刪除等操作相關(guān)技巧,需要的朋友可以參考下2016-09-09