慢慢来,这次实现了向任意方向扩展!
复制代码 代码如下:
<!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>Untitled Document</title>
<style type="text/css">
<!--
#apDiv1 {
position:absolute;
left:300px;
top:100px;
width:100px;
height:100px;
z-index:1;
background-color: #FF00FF;
}
#apDiv2 {
position:absolute;
left:402px;
top:100px;
width:100px;
height:100px;
z-index:2;
background-color: #00FFFF;
}
#apDiv3 {
position:absolute;
left:402px;
top:200px;
width:100px;
height:100px;
z-index:3;
background-color: #99FF00;
}
#apDiv4 {
position:absolute;
left:300px;
top:200px;
width:100px;
height:100px;
z-index:4;
background-color: #FFFF00;
}
-->
</style>
</head>
<body>
<div id="apDiv1"></div>
<div id="apDiv2"></div>
<div id="apDiv3"></div>
<div id="apDiv4"></div>
</body>
</html>
<script language="javascript" type="text/javascript">
function $(pId){
return document.getElementById(pId);
}
function JPos(){
}
JPos.getAbsPos = function(pTarget){
var _x = 0;
var _y = 0;
while(pTarget.offsetParent){
_x += pTarget.offsetLeft;
_y += pTarget.offsetTop;
pTarget = pTarget.offsetParent;
}
_x += pTarget.offsetLeft;
_y += pTarget.offsetTop;
return {x:_x,y:_y};
}
function JAniObj(){
this.obj = null;
this.interval = null;
this.orgPos = null;
this.targetPos = null;
this.orgSize = {w:50,y:50}; //初始长宽
this.targetSize = {w:100,y:100}; //目标长宽
this.step = {x:10,y:10}; //步长 x:x方向 y:y方向
this.alpha = {s:10,e:90,t:10}; //透明度,s初始,e结束,t步长
}
function JAni(){
var self = this;
var aniObjs = {};
var getCurrentStyleProperty = function(pObj,pProperty){
try{
if(pObj.currentStyle)
return eval("pObj.currentStyle." + pProperty);
else
return document.defaultView.getComputedStyle(pObj,"").getPropertyValue(pProperty);
}catch(e){
alert(e);
}
}
this.popup = function(pDiv,pOrgSize,pTargetSize,pStep,pAlpha){
var aniObj = new JAniObj();
aniObjs[pDiv] = aniObj;
with(aniObj){
obj = $(pDiv);
orgPos = JPos.getAbsPos(obj);
orgSize = pOrgSize;
targetSize = pTargetSize;
step = pStep;
alpha = pAlpha;
with(obj.style){
overflow = "hidden";
position = "absolute";
width = pOrgSize.w + "px";
height = pOrgSize.h + "px";
left = orgPos.x + "px";
top = orgPos.y + "px";
if(document.all){
filter = "Alpha(opacity=" + pAlpha.s + ")";
}else
opacity = pAlpha.s / 100;
}
}
aniObj.interval = setInterval("popup_('" + pDiv + "')",10);
}
popup_ = function(pDivId){
pObj = aniObjs[pDivId];
var w = parseInt(pObj.obj.style.width);
var h = parseInt(pObj.obj.style.height);
if(w >= Math.abs(pObj.targetSize.w) && h >= Math.abs(pObj.targetSize.h)){
clearInterval(pObj.interval);
if(document.all)
pObj.obj.style.filter = "Alpha(opacity=" + pObj.alpha.e + ")";
else
pObj.obj.style.opacity = pObj.alpha.e / 100;
delete aniObjs[pObj.obj.id];
}else{
if(w < Math.abs(pObj.targetSize.w))
w += pObj.step.x;
if(h < Math.abs(pObj.targetSize.h))
h += pObj.step.y;
if(document.all){
var pattern = /opacity=(\d{1,3})/;
var result = pattern.exec(pObj.obj.style.filter);
if(result != null){
if(result[1] < pObj.alpha.e)
pObj.obj.style.filter = "Alpha(opacity=" + (result[1] + pObj.alpha.t) + ")"
else
pObj.obj.style.filter = "Alpha(opacity=" + pObj.alpha.e + ")";
}
}else{
if(pObj.obj.style.opacity < pObj.alpha.e / 100){
pObj.obj.style.opacity = parseFloat(pObj.obj.style.opacity) + pObj.alpha.t / 100;
}else
pObj.obj.style.opacity = pObj.alpha.e / 100;
}
}
pObj.obj.style.width = w + "px";
pObj.obj.style.height = h + "px";
if(pObj.targetSize.w < 0){
var vLeft = parseInt(getCurrentStyleProperty(pObj.obj,"left"));
vLeft = isNaN(vLeft) ? 0 : vLeft;
pObj.obj.style.left = vLeft - pObj.step.x + "px";
}
if(pObj.targetSize.h < 0){
var vTop = parseInt(getCurrentStyleProperty(pObj.obj,"top"));
vTop = isNaN(vTop) ? 0 : vTop;
pObj.obj.style.top = vTop - pObj.step.y + "px";
}
}
}
var ani = new JAni();
ani.popup(
"apDiv1",
{w:50,h:50}, //初始长宽
{w:200,h:200}, //目标长宽
{x:8,y:8}, //步长
{s:10,e:80,t:10}//透明度 起始,结束,步长
);
ani.popup(
"apDiv2",
{w:50,h:50}, //初始长宽
{w:-200,h:200}, //目标长宽
{x:8,y:8}, //步长
{s:10,e:40,t:2}//透明度 起始,结束,步长
);
ani.popup(
"apDiv3",
{w:50,h:50}, //初始长宽
{w:-200,h:-200},//目标长宽
{x:8,y:8}, //步长
{s:10,e:40,t:10}//透明度 起始,结束,步长
);
ani.popup(
"apDiv4",
{w:50,h:50}, //初始长宽
{w:200,h:-200},//目标长宽
{x:8,y:8}, //步长
{s:10,e:50,t:10}//透明度 起始,结束,步长
);
</script>
复制代码 代码如下:
<!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>Untitled Document</title>
<style type="text/css">
<!--
#apDiv1 {
position:absolute;
left:300px;
top:100px;
width:100px;
height:100px;
z-index:1;
background-color: #FF00FF;
}
#apDiv2 {
position:absolute;
left:402px;
top:100px;
width:100px;
height:100px;
z-index:2;
background-color: #00FFFF;
}
#apDiv3 {
position:absolute;
left:402px;
top:200px;
width:100px;
height:100px;
z-index:3;
background-color: #99FF00;
}
#apDiv4 {
position:absolute;
left:300px;
top:200px;
width:100px;
height:100px;
z-index:4;
background-color: #FFFF00;
}
-->
</style>
</head>
<body>
<div id="apDiv1"></div>
<div id="apDiv2"></div>
<div id="apDiv3"></div>
<div id="apDiv4"></div>
</body>
</html>
<script language="javascript" type="text/javascript">
function $(pId){
return document.getElementById(pId);
}
function JPos(){
}
JPos.getAbsPos = function(pTarget){
var _x = 0;
var _y = 0;
while(pTarget.offsetParent){
_x += pTarget.offsetLeft;
_y += pTarget.offsetTop;
pTarget = pTarget.offsetParent;
}
_x += pTarget.offsetLeft;
_y += pTarget.offsetTop;
return {x:_x,y:_y};
}
function JAniObj(){
this.obj = null;
this.interval = null;
this.orgPos = null;
this.targetPos = null;
this.orgSize = {w:50,y:50}; //初始长宽
this.targetSize = {w:100,y:100}; //目标长宽
this.step = {x:10,y:10}; //步长 x:x方向 y:y方向
this.alpha = {s:10,e:90,t:10}; //透明度,s初始,e结束,t步长
}
function JAni(){
var self = this;
var aniObjs = {};
var getCurrentStyleProperty = function(pObj,pProperty){
try{
if(pObj.currentStyle)
return eval("pObj.currentStyle." + pProperty);
else
return document.defaultView.getComputedStyle(pObj,"").getPropertyValue(pProperty);
}catch(e){
alert(e);
}
}
this.popup = function(pDiv,pOrgSize,pTargetSize,pStep,pAlpha){
var aniObj = new JAniObj();
aniObjs[pDiv] = aniObj;
with(aniObj){
obj = $(pDiv);
orgPos = JPos.getAbsPos(obj);
orgSize = pOrgSize;
targetSize = pTargetSize;
step = pStep;
alpha = pAlpha;
with(obj.style){
overflow = "hidden";
position = "absolute";
width = pOrgSize.w + "px";
height = pOrgSize.h + "px";
left = orgPos.x + "px";
top = orgPos.y + "px";
if(document.all){
filter = "Alpha(opacity=" + pAlpha.s + ")";
}else
opacity = pAlpha.s / 100;
}
}
aniObj.interval = setInterval("popup_('" + pDiv + "')",10);
}
popup_ = function(pDivId){
pObj = aniObjs[pDivId];
var w = parseInt(pObj.obj.style.width);
var h = parseInt(pObj.obj.style.height);
if(w >= Math.abs(pObj.targetSize.w) && h >= Math.abs(pObj.targetSize.h)){
clearInterval(pObj.interval);
if(document.all)
pObj.obj.style.filter = "Alpha(opacity=" + pObj.alpha.e + ")";
else
pObj.obj.style.opacity = pObj.alpha.e / 100;
delete aniObjs[pObj.obj.id];
}else{
if(w < Math.abs(pObj.targetSize.w))
w += pObj.step.x;
if(h < Math.abs(pObj.targetSize.h))
h += pObj.step.y;
if(document.all){
var pattern = /opacity=(\d{1,3})/;
var result = pattern.exec(pObj.obj.style.filter);
if(result != null){
if(result[1] < pObj.alpha.e)
pObj.obj.style.filter = "Alpha(opacity=" + (result[1] + pObj.alpha.t) + ")"
else
pObj.obj.style.filter = "Alpha(opacity=" + pObj.alpha.e + ")";
}
}else{
if(pObj.obj.style.opacity < pObj.alpha.e / 100){
pObj.obj.style.opacity = parseFloat(pObj.obj.style.opacity) + pObj.alpha.t / 100;
}else
pObj.obj.style.opacity = pObj.alpha.e / 100;
}
}
pObj.obj.style.width = w + "px";
pObj.obj.style.height = h + "px";
if(pObj.targetSize.w < 0){
var vLeft = parseInt(getCurrentStyleProperty(pObj.obj,"left"));
vLeft = isNaN(vLeft) ? 0 : vLeft;
pObj.obj.style.left = vLeft - pObj.step.x + "px";
}
if(pObj.targetSize.h < 0){
var vTop = parseInt(getCurrentStyleProperty(pObj.obj,"top"));
vTop = isNaN(vTop) ? 0 : vTop;
pObj.obj.style.top = vTop - pObj.step.y + "px";
}
}
}
var ani = new JAni();
ani.popup(
"apDiv1",
{w:50,h:50}, //初始长宽
{w:200,h:200}, //目标长宽
{x:8,y:8}, //步长
{s:10,e:80,t:10}//透明度 起始,结束,步长
);
ani.popup(
"apDiv2",
{w:50,h:50}, //初始长宽
{w:-200,h:200}, //目标长宽
{x:8,y:8}, //步长
{s:10,e:40,t:2}//透明度 起始,结束,步长
);
ani.popup(
"apDiv3",
{w:50,h:50}, //初始长宽
{w:-200,h:-200},//目标长宽
{x:8,y:8}, //步长
{s:10,e:40,t:10}//透明度 起始,结束,步长
);
ani.popup(
"apDiv4",
{w:50,h:50}, //初始长宽
{w:200,h:-200},//目标长宽
{x:8,y:8}, //步长
{s:10,e:50,t:10}//透明度 起始,结束,步长
);
</script>
标签:
JS,动画效果
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com
暂无“JS动画效果代码3”评论...
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。