清醒时做事,糊涂时读书,大怒时睡觉,无聊时关注图老师为大家准备的精彩内容。下面为大家推荐初探 HTML 组件 - 定义方法,无聊中的都看过来。
【 tulaoshi.com - Web开发 】
我们可以使用 PUBLIC:METHOD 元素来定义 HTC 的方法集,如下例所示:
PUBLIC:METHOD NAME="startFlying" /
当我们定义了一个方法后,我们就可以在 HTC 中直接来调用它。请看下面的例子:
PUBLIC:METHOD NAME="tick" /
PUBLIC:METHOD NAME="startFlying" /
:
SCRIPT LANGUAGE="JScript"
var currCount;
var flyCount;
var flying;
var msecs;
var oTop, oLeft;
msecs = 50;
flyCount = 20;
flying = false;
runtimeStyle.position = "relative";
runtimeStyle.visibility = "hidden";
window.attachEvent("onload", onload);
function onload()
{
// delay commences from the window.onLoad event
if (delay != "none")
{
window.setTimeout(uniqueID+".tick()", delay);
}
}
function tick()
{
if (flying == false)
{
startFlying();
}
else
{
doFly();
}
}
function startFlying()
{
if (fromX==null && fromY==null)
{
if (from=="top")
{
runtimeStyle.posTop = -offsetTop-offsetHeight;
}
else if (from=="bottom")
{
runtimeStyle.posTop = element.document.body.clientHeight;
}
else if (from=="right" )
{
runtimeStyle.posLeft = element.document.body.clientWidth;
}
else
{
runtimeStyle.posLeft = -offsetLeft-offsetWidth;
}
}
else
{
runtimeStyle.posTop = fromY;
runtimeStyle.posLeft = fromX;
}
runtimeStyle.visibility = "visible";
flying = true;
oTop = runtimeStyle.posTop;
oLeft = runtimeStyle.posLeft;
currCount = 0;
doFly();
}
function doFly()
{
var dt, dl;
currCount++;
dt = oTop / flyCount;
dl = oLeft / flyCount;
runtimeStyle.posTop -= dt;
runtimeStyle.posLeft -= dl;
if (currCount flyCount)
{
window.setTimeout(uniqueID+".tick();", msecs);
}
else
{
runtimeStyle.posTop = 0;
runtimeStyle.posLeft = 0;
flying = false;
evObj = createEventObject();
evObj.setAttribute("resulty", uniqueID);
finished.fire(evObj);
}
}
/SCRIPT
来源:http://www.tulaoshi.com/n/20160219/1626641.html
看过《初探 HTML 组件 - 定义方法》的人还看了以下文章 更多>>