js匀速滑动div
2014-02-19 09:49
49 查看
<html>
<head>
<style type="text/css">
#aini{ width:1px; height:50px; background:blue; }
#aini2{ width:50px; height:50px; background:blue; left:20px; }
</style>
<script>
function pageX(el){
return el.offsetParent?el.offsetLeft+pageX(el.offsetParent):el.offsetLeft;
};
function pageY(el){
return el.offsetParent?el.offsetTop+pageY(el.offsetParent):el.offsetTop;
};
var tween = {
/*
t=0~d , b=??? ,c = ???? ? d = ???-???
*/
Linear: function(t,b,c,d){ return c*t/d + b; },
};
function aini(el,opt){
el.style.position="absolute";
var duration = opt.duration||1000;
var t = 0,d=Math.floor(duration/16);
var X = pageX(el),Y=pageY(el);
var dx = opt.X-X,dy = opt.Y-Y;
function _aini(){
if(t<d){
el.style.left=tween.Linear(t,X,dx,d)+"px";
//el.style.top=tween.Linear(t,0,dy,d)+X+"px";
//el.style.top=PY+"px";
t++;
setTimeout(arguments.callee,100);
}else{
el.style.left=opt.X+"px";
//el.style.top=opt.Y+"px";
}
};
_aini();
}
//window.onload = function(){
//aini(document.getElementById('aini'),{X:200,Y:200});
//}
</script>
</head>
<body>
<p><input type="button" onClick="aini(document.getElementById('aini'),{X:800,Y:200});" value="点下我看看" /></p>
<div><div id="aini"></div></div>
</body>
</html>
<head>
<style type="text/css">
#aini{ width:1px; height:50px; background:blue; }
#aini2{ width:50px; height:50px; background:blue; left:20px; }
</style>
<script>
function pageX(el){
return el.offsetParent?el.offsetLeft+pageX(el.offsetParent):el.offsetLeft;
};
function pageY(el){
return el.offsetParent?el.offsetTop+pageY(el.offsetParent):el.offsetTop;
};
var tween = {
/*
t=0~d , b=??? ,c = ???? ? d = ???-???
*/
Linear: function(t,b,c,d){ return c*t/d + b; },
};
function aini(el,opt){
el.style.position="absolute";
var duration = opt.duration||1000;
var t = 0,d=Math.floor(duration/16);
var X = pageX(el),Y=pageY(el);
var dx = opt.X-X,dy = opt.Y-Y;
function _aini(){
if(t<d){
el.style.left=tween.Linear(t,X,dx,d)+"px";
//el.style.top=tween.Linear(t,0,dy,d)+X+"px";
//el.style.top=PY+"px";
t++;
setTimeout(arguments.callee,100);
}else{
el.style.left=opt.X+"px";
//el.style.top=opt.Y+"px";
}
};
_aini();
}
//window.onload = function(){
//aini(document.getElementById('aini'),{X:200,Y:200});
//}
</script>
</head>
<body>
<p><input type="button" onClick="aini(document.getElementById('aini'),{X:800,Y:200});" value="点下我看看" /></p>
<div><div id="aini"></div></div>
</body>
</html>
相关文章推荐
- js控制div匀速移动和停止
- js实现div滑动收起效果
- js简单实现div宽度匀速增加/减小
- js或jQ监测div的高度
- js制作一个简单的div弹窗:
- 移动应用滑动屏幕方向判断解决方案,JS判断手势方向
- js用斜率判断鼠标进入div的四个方向
- JS实现滚动监听以及滑动到顶部【转】
- JS得到div的value值(网上资料保存)
- 解决用jquery load加载页面到div时,不执行页面的js
- 纯JS轮播图,左右箭头/轮播点,自动+自适应屏幕+手机触屏滑动
- JS实现点击按钮控制Div变宽、增高及调整背景色的方法
- js实现的八点拖动修改div大小的代码
- js 监听移动端web触屏事件 滑动响应
- JS当前页面登录注册框,固定DIV,底层阴影的实例代码
- js指定步长实现单方向匀速运动
- JS实现滚动监听以及滑动到顶部
- js新手学习中:js创建div和img并把img插入div中
- js实现水平滑动和垂直滑动
- js+div 选项卡