【发布时间】:2014-08-27 12:45:18
【问题描述】:
我正在尝试将一串文本添加到我的 Spinner 图形中。例如,我希望能够将文本放置在 below、next to 或 inside 微调轮中。问题是,我不知道该怎么做。另外,我只想对文本本身进行半动画处理(如果动画太多,用户可能无法阅读)。
- 用 Raphael 创建的微调器:
- 目标结果的 HTML 示例模型:http://jsfiddle.net/mnbishop017/4Enrk/
微调器代码(JavaScript > Raphaël):
window.onload = function () {
function spinner(holderid, R1, R2, count, stroke_width, color) {
var sectorsCount = count || 12,
color = color || "#fff",
width = stroke_width || 15,
r1 = Math.min(R1, R2) || 35,
r2 = Math.max(R1, R2) || 60,
cx = r2 + width,
cy = r2 + width,
r = Raphael(holderid, r2 * 2 + width * 2, r2 * 2 + width * 2),
sectors = [],
opacity = [],
beta = 2 * Math.PI / sectorsCount,
pathParams = {
stroke: color,
"stroke-width": width,
"stroke-linecap": "round"
};
Raphael.getColor.reset();
for (var i = 0; i < sectorsCount; i++) {
var alpha = beta * i - Math.PI / 2,
cos = Math.cos(alpha),
sin = Math.sin(alpha);
opacity[i] = 1 / sectorsCount * i;
sectors[i] = r.path([
["M", cx + r1 * cos, cy + r1 * sin],
["L", cx + r2 * cos, cy + r2 * sin]
]).attr(pathParams);
if (color == "rainbow") {
sectors[i].attr("stroke", Raphael.getColor());
}
}
var tick;
(function ticker() {
opacity.unshift(opacity.pop());
for (var i = 0; i < sectorsCount; i++) {
sectors[i].attr("opacity", opacity[i]);
}
r.safari();
tick = setTimeout(ticker, 1000 / sectorsCount);
})();
return function () {
clearTimeout(tick);
r.remove();
};
}
spinner("holder", 0, 120, 17, 2, "#000");
// spinner("holder", -120, 120, 17, 2, "#005075"); Second spinner inserted above first spinner
};
所需结果的样机(HTML)
<div>
<!-- .placeholder is where the main Loading graphic (or animation) appears -->
<div class="placeholder"></div>
<!-- .text is where the Loading text appears: -->
<!-- next to the graphic, vertically aligned to the middle -->
<div class="text">loading</div>
</div>
【问题讨论】:
标签: javascript jquery css svg raphael