根据官方文档examples里的animated-hotspots中代码可以看到热点动画的原理就是做一个很长的图片,不断切换显示的位置。
以下是官方的代码:
<!-- 关键动画代码 -->
<action name="do_crop_animation" scope="local" args="framewidth, frameheight, framerate">
<!-- define local variables -->
calc(local.xframes, (caller.imagewidth /framewidth) BOR 0);
calc(local.frames, xframes * ((caller.imageheight / frameheight) BOR 0));
def(local.frame, integer, 0);
<!-- set the first frame -->
calc(caller.crop, '0|0|' + framewidth + '|' + frameheight);
<!-- do the animation -->
setinterval(calc('crop_anim_' + caller.name), calc(1.0 / framerate),
if(caller.loaded,
inc(frame);
if(frame GE frames, if(caller.onlastframe !== null, callwith(caller, onlastframe() ) ); set(frame,0); );
mod(xpos, frame, xframes);
div(ypos, frame, xframes);
Math.floor(ypos);
mul(xpos, framewidth);
mul(ypos, frameheight);
calc(caller.crop, xpos + '|' + ypos + '|' + framewidth + '|' + frameheight);
,
<!-- stop the interval when the hotspot gets removed -->
clearinterval(calc('crop_anim_' + caller.name));
);
);
</action>
<!-- 关键动画代码 -->
<!-- example hotspots -->
<hotspot name="spot1" url="animatedhotspot_white.png" onloaded="do_crop_animation(64,64, 60);" ath="-15" atv="-12" onclick="looktohotspot(get(name),65);" />
<!-- 这里url换上你自己图片地址就行,do_crop_animation(64,64, 60)这里前2个数字是图片显示出来大小,最后一个是切换频率 -->