0
新手在這裏,我有拉斐爾2.1.4一個簡單的時鐘基於教程的一切呈現在頁面上不錯,但處理不轉動。然而它似乎對Raphael 1.5.X起作用。簡單的時鐘與拉斐爾2.1.4
你能告訴我我做錯了什麼嗎?
碼筆頁附 http://codepen.io/scorpion_rain/pen/dGrmQj
代碼JS: 在window.onload =在瀏覽器中出現錯誤 '不能找到可變hourHand'
的控制檯功能(){var cWidth = 800, cHeight = 600;
var paper = new Raphael(document.getElementById('canvas_container'), cWidth, cHeight);
var clockBgX = 200, clockBgY = 300, clockBgRadius = 100;
var cBgCol = '#f5f5f5', cBgStrokeCol = '#444444', cBgStrokeWidth = '5';
var centerDialX = clockBgX, centerDialY = clockBgY;
var hourHandStrokeCol = "#444444", hourHandStrokeWidth = "5";
var minuteHandStrokeCol = "#444444", minuteHandStrokeWidth = "3";
var secondsHandStrokeCol = "#444444", secondsHandStrokeWidth = "2";
var pinDotX = clockBgX, pinDotY = clockBgY, pinDotRadius = 5, pinDotFill = "#000000";
// main clock background and number display
function mainClockBg(){
var clockBg = paper.circle(clockBgX, clockBgY, clockBgRadius); // outer circle
clockBg.attr({ "fill": cBgCol, // inner background
"stroke": cBgStrokeCol,
"stroke-width": cBgStrokeWidth })
var radius = Math.PI/180; // converting from degrees to radian
var cx = centerDialX; // center of dial - horizontal
var cy = centerDialY; // center of dial - vertical
var r = 90; // radius distance
var startA = -90; // start of numbers
var angle = 30; // distance between numbers | 12/360 = 12 stops
var x; // circle distance inner marker
var y; // circle distance outer marker
var endA; // end of text
// adding numbers to the dial
for(i = 1; i < 13; i++){
endA = startA + angle;
x = cx + r * Math.cos(endA * radius);
y = cy + r * Math.sin(endA * radius);
paper.text(x, y, i + "");
startA = endA;
}
}
function dialsDisplay(){
var hourHand = paper.path("M200, 300L200, 230");
hourHand.attr({
"stroke": hourHandStrokeCol,
"stroke-width": hourHandStrokeWidth
});
var minuteHand = paper.path("M200, 300L200, 220");
minuteHand.attr({
"stroke": minuteHandStrokeCol,
"stroke-width": minuteHandStrokeWidth
})
var secondsHand = paper.path("M200, 300L200, 216");
secondsHand.attr({
"stroke": secondsHandStrokeCol,
"stroke-width": secondsHandStrokeWidth
})
var pinDot = paper.circle(pinDotX, pinDotY, pinDotRadius);
pinDot.attr({
"fill": pinDotFill
});
updateClock();
setInterval("updateClock()", 1000);
}
function updateClock(){
var time = new Date();
var hours = time.getHours();
var minutes = time.getMinutes();
var seconds = time.getSeconds();
hourHand.rotate( 30 * hours + (minutes/2.5), 200, 300 );
minuteHand.rotate(6 * minutes, 200, 300);
secondsHand.rotete(6 * seconds, 200, 300);
}
mainClockBg();
dialsDisplay();
}
任何幫助表示讚賞 乾杯。
謝謝你,我想用手中的運動是因爲它有RaphaelJS(2.1.4)的新版本,如果我用的是舊版本如。 1.5.x等工作。 – Zinox