国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JavaScript > 正文

Javascript實(shí)現(xiàn)重力彈跳拖拽運(yùn)動(dòng)效果示例

2019-11-20 22:36:01
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
演示地址:
http://www.ihuxu.com/project/gcdmove/

調(diào)用示例:
var GCDM = gcdMove(oDiv,100,0);
GCDM.startMove();//開(kāi)始運(yùn)動(dòng)
GCDM.stopMove();//結(jié)束運(yùn)動(dòng)
該段JS代碼已經(jīng)封裝好了,代碼如下:
簡(jiǎn)要說(shuō)明 - obj為要改動(dòng)的對(duì)象元素,通常為某個(gè)div;iSpeedX,iSpeedY為div出師的橫向(右側(cè)),豎向(下)的初始速度,當(dāng)然也可以設(shè)為零。
復(fù)制代碼 代碼如下:

/**
* @Desc 重力碰撞拖拽運(yùn)動(dòng) - Gravity Crash Drag Move(gcdMove)
* @Author GenialX
* @URL www.ihuxu.com
* @QQ 2252065614
* @Date 2013.06.22
*/
function gcdMove(obj, iSpeedX, iSpeedY) {
_this = this;//public identifier
//construct fun
var gcdMove;
//self defined fun
var start;
_this.startMove;
//other var
var iTimer;
var iLastX = 0;
var iLastY = 0;
//construct fun
start = function() {
clearInterval(iTimer);
iTimer = setInterval(function() {
iSpeedY += 3;
var l = obj.offsetLeft + iSpeedX;
var t = obj.offsetTop + iSpeedY;
if (t >= document.documentElement.clientHeight - obj.offsetHeight) {
iSpeedY *= -0.8;
iSpeedX *= 0.8;
t = document.documentElement.clientHeight - obj.offsetHeight;
} else if (t <= 0) {
iSpeedY *= -1;
iSpeedX *= 0.8;
t = 0;
}
if (l >= document.documentElement.clientWidth - obj.offsetWidth) {
iSpeedX *= -0.8;
l = document.documentElement.clientWidth - obj.offsetWidth;
} else if (l <= 0) {
iSpeedX *= -0.8;
l = 0;
}
if (Math.abs(iSpeedX) < 1) {
iSpeedX = 0;
}
if (iSpeedX == 0 && iSpeedY == 0 && t == document.documentElement.clientHeight - obj.offsetHeight) {
clearInterval(iTimer);
}
obj.style.left = l + 'px';
obj.style.top = t + 'px';
}, 30);
}
_this.startMove = function(){
obj.onmousedown = function(ev) {
clearInterval(iTimer);
var oEvent = ev || event;
var disX = oEvent.clientX - obj.offsetLeft;
var disY = oEvent.clientY - obj.offsetTop;
document.onmousemove = function(ev) {
var oEvent = ev || event;
var l = oEvent.clientX - disX;
var t = oEvent.clientY - disY;
obj.style.left = l + 'px';
obj.style.top = t + 'px';
if(iLastX ==0){
iLastX = l;
}
if(iLastY == 0){
iLastY = t;
}
iSpeedX = l - iLastX;
iSpeedY = t - iLastY;
iLastX = l;
iLastY = t;
}
}
obj.onmouseup = function() {
document.onmousedown = null;
document.onmousemove = null;
document.onmouseup = null;
start();
}
start();
}
_this.stopMove = function(){
clearInterval(iTimer);
obj.onmousedown = null;
document.onmousemove = null;
obj.onmouseup = null;
iLastX = 0;
iLastY = 0;
iSpeedX = 0;
iSpeedY = 0;
disX = 0;
disY = 0;
}
//CONSTRUCT AREA
var gcdMove = function() {
if (!iSpeedX) {
iSpeedX = 0;
}
if (!iSpeedY) {
iSpeedY = 0;
}
}
gcdMove();
}
發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 凌海市| 松桃| 贵溪市| 屯门区| 长宁区| 巨鹿县| 广丰县| 习水县| 正蓝旗| 东城区| 民乐县| 汝阳县| 铁岭县| 海南省| 武平县| 哈巴河县| 蒙自县| 林口县| 佛冈县| 油尖旺区| 扶余县| 宜城市| 靖边县| 高邮市| 红原县| 云阳县| 太仆寺旗| 巩义市| 潜江市| 开远市| 定州市| 黎平县| 屏山县| 信宜市| 桓台县| 静海县| 宜丰县| 洛川县| 建平县| 缙云县| 广丰县|