首页 > 语言 > JavaScript > 正文

JS动画效果代码3

2024-05-06 14:18:18
字体:
来源:转载
供稿:网友
慢慢来,这次实现了向任意方向扩展!
代码如下:
<!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};  //初始长宽 
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选