*purpleendurer修正了原文中的一些錯誤
你可以通過IE為你的HTML元素添加行為
Macromedia Flash可以使開發者免受網絡浏覽器與互操作解決方案的限制
例如
為HTML添加行為的能力是設計的一個關鍵部分
<style>DIV
從這段腳本中
表A中包含了為我們的嵌套<DIV>對象建立行為的所有代碼
表 A
<public:component lightweight=
<public:attach event=
<public:attach event=
<public:attach event=
<public:attach event=
<public:attach event=
<public:attach event=
<public:attach event=
<public:method name=
<public:property name=
<public:property name=
<script language=
var m_bStarted = false;
var m_bMoving = false;
var m_clickPoint = null;
var m_tStart =
var m_tEnd =
var m_ptStart = null;
var m_Slope = null;
var m_interval =
var m_isMoving = false;
var m_trash =
var m_dX =
var m_dY =
var m_vectX =
var m_vectY =
var m_pNode = null;
var m_bounds = [];
var BOUNDS = {
var m_dimensions = [];
var DIMS = {
function Init()
{
element
var m_pNode = element
m_bounds = [
parseInt(m_pNode
parseInt(m_pNode
];
m_dimensions = [
Node parseInt(element
parseInt(element
];
}
function element_onmousedown()
{
m_bStarted = true;
m_tStart = new Date();
clearInterval(m_interval);
m_Slope = null;
m_ptStart = null;
m_trash =
m_dX =
m_dY =
m_vectX =
m_vectY =
m_clickPoint = new Point(event
m_ptStart = new Point(part(element
}
function element_onmouseup()
{
if (!m_bMoving) return;
m_bMoving = false;
m_bStarted = false;
m_tEnd = new Date();
var t = m_tEnd
var lPoint = new Point(event
m_Slope = Geometry
var ptEnd = m_Slope
element
element
var spd =
if (m_Slope
{
spd = Math
}
else
{
spd = (m_Slope
}
if (spd >
m_dX = m_Slope
m_dY = m_Slope
if (m_dX !=
if (m_dY !=
startMove(element
}
function element_onmousemove()
{
m_bMoving = m_bStarted;
if (!m_bMoving) return;
var lPoint = new Point(event
var lSlope = Geometry
var ptEnd = lSlope
element
element
}
function element_onselectstart()
{
event
return false;
}
function element_ondragstart()
{
event
return false;
}
function get_clickPoint()
{
return m_clickPoint;
}
function put_clickPoint(o)
{
if (typeof(o) ==
{
m_clickPoint = o;
}
else
{
alert(
}
}
function get_interval()
{
return m_interval;
}
function put_interval(n)
{
m_interval = n;
}
function moveMe()
{
if (m_isMoving) return;
setTimeout(
var newX = parseInt(element
var newY = parseInt(element
var dXabs = Math
var dYabs = Math
if (dXabs > dYabs)
{
//divide both by deltaX
//each call move X by
//if iteration >
//and add remainder back on Y
newX += m_vectX;
var l_step = (m_dY/m_dX) *
m_trash = m_trash + l_step;
if (m_trash >
{
newY += m_vectY;
m_trash
}
}
else
{
//vice
newY += m_vectY;
var l_step = (m_dX/m_dY) *
m_trash = m_trash + l_step;
if (m_trash >
{
newX += m_vectX;
m_trash
}
}
if (newX <= m_bounds[BOUNDS
{
newX = m_bounds[BOUNDS
m_vectX *=
}
else if ((newX + m_dimensions[DIMS
{
newX = m_bounds[BOUNDS
m_vectX *=
}
if (newY <= m_bounds[BOUNDS
{
newY = m_bounds[BOUNDS
m_vectY *=
}
else if ((newY + m_dimensions[DIMS
{
newY = m_bounds[BOUNDS
m_vectY *=
}
element
element
setTimeout(
}
</script>
</public:component>
如果你注意到了腳本的頂部
當組件(在裝載事件中)初始化時
當用戶在屏幕上拖動對象時— element_onmousemove() —對象的位置發生改變
當用戶釋放鼠標按鈕— element_onmouseup() —或是鼠標脫離了對象區域— element_onmouseout() —時
在間隔中斷事件— moveMe() —中
如果對象的新位置位於限定元素之外
表B是含有這些組件的HTML頁面
表 B 的內容
<html>
<head>
<style>
DIV
{
width:
height:
border:
overflow: hidden;
}
DIV
{
position:absolute;
left:
top:
border:
behavior: url(component
cursor: hand;
}
</style>
<script language=
function Point(pX
{
this
this
}
function CSlope(P
{
this
this
this
}
function _slopeAdd(P
{
var lPoint = new Point((P
return lPoint;
}
CSlope
function CGeometry() {}
function _slope(P
{
var lSlope = new CSlope(P
return lSlope;
}
CGeometry
var Geometry = new CGeometry();
var objStack = [];
function startMove(obj
{
var id = objStack
objStack[id
}
</script>
</head>
<body >
<center>
<div class=
<div class=
</div>
</center>
</body>
</html>
HTML頁面不過是包含<DIV>及作為組件元素的嵌套<DIV>
拷貝這些代碼並將它粘貼到你自己的文件中
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19564.html