Spinner 그래픽에 텍스트 문자열을 추가하려고합니다. 예를 들어, 아래 , 옆 또는 스피너 휠 내부에 텍스트를 배치 할 수 있기를 원합니다 . 문제는 어떻게해야할지 모르겠다는 것입니다. 또한 텍스트 자체 만 반 애니메이션화하고 싶습니다 (너무 많이 애니메이션하면 사용자가 읽을 수 없을 수도 있음).
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
};
<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>
제공하는 데모에서 2 개의 라이브러리를 혼합하고 있으며, 스피너는 Raphael이고 로딩 텍스트는 jQuery입니다. 나는 여기에 두 가지의 조합을 만들었습니다 -http : //jsfiddle.net/robschmuecker/vM9uk/13/- 이것은이 HTML의 조합입니다.
<div class="box">
<!-- .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 -->
<div class="text">loading <span class="dot">.</span>
<span class="dot">.</span>
<span class="dot">.</span>
</div>
</div>
이 JavaScript는 RaphaelJS와 jQuery를 모두 포함했습니다.
$(document).ready(function () {
var firstDot = $(".dot:first-of-type");
var midDot = $(".dot:nth-of-type(2)");
var lastDot = $(".dot:last-of-type");
firstDot.hide();
midDot.hide();
lastDot.hide();
$(".placeholder,.text").hide().fadeIn(1000, function () {
var interv = 0;
interv = setInterval(function () {
firstDot.fadeIn(250, function () {
midDot.fadeIn(250, function () {
lastDot.fadeIn(250);
});
}).delay(1000).fadeOut(250, function () {
midDot.fadeOut(250, function () {
lastDot.fadeOut(250);
});
});
}, 3000)
});
});
그런 다음 로딩 텍스트와 스피너의 위치를 조작하는 간단한 CSS가 있습니다. 그러나 이것은 RaphaelJS와 jQuery를 모두로드해야하기 때문에 이상적이지 않을 수 있습니다. 순수한 RaphaelJS에서도이 작업을 수행 할 수 있습니다. : 여기에 기준을 살펴 가지고 http://raphaeljs.com/reference.html 의 아이디어를 얻을 수 및 데모 무엇을 당신이 원하는합니다. 예를 들어, 여기에서는 스피너 중간에 간단한 텍스트 요소를 추가하고 연속 루프에서 페이드 인 / 아웃합니다. (데모 : http://jsfiddle.net/robschmuecker/vM9uk/14/ )
tempText = r.text(R2, R2, "Loading ...");
function fadeTextOut(){
tempText.animate({opacity: 0}, 2500, fadeTextIn);
}
function fadeTextIn(){
tempText.animate({opacity: 1}, 2500, fadeTextOut);
}
fadeTextOut();
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다